Skip to content

Commit

Permalink
Improvements after review
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Oct 4, 2023
1 parent 5ff1fe4 commit d8469d7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tests/pubsub/testgossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -954,39 +954,41 @@ suite "GossipSub":

return (nodes, gossip0, gossip1)

proc getCurrentDisconnections(): float64 =
proc currentDisconnections(): float64 =
try:
libp2p_gossipsub_peers_rate_limit_disconnections.valueByName("libp2p_gossipsub_peers_rate_limit_disconnections_total", @["nim-libp2p"])
except KeyError:
0

asyncTest "e2e - GossipSub should process valid messages":
# TODO - Once the rate limit actually disconnects peers, we must update the rate limit tests bellow to check for disconnections
asyncTest "e2e - GossipSub should not rate limit decodable messages below the size allowed":
let disconnections = currentDisconnections()
let (nodes, gossip0, gossip1) = await initializeGossipTest()

gossip0.broadcast(gossip1.mesh["foobar"], RPCMsg(
messages: @[Message(topicIDs: @["foobar"], data: "Valid data".toBytes)])
)
await sleepAsync(300.millis)

check getCurrentDisconnections() == 0
check currentDisconnections() == disconnections

await stopNodes(nodes)

asyncTest "e2e - GossipSub should rate limit undecodable messages above what is allowed":
let disconnections = getCurrentDisconnections()
asyncTest "e2e - GossipSub should rate limit undecodable messages above the size allowed":
let disconnections = currentDisconnections()

let (nodes, gossip0, gossip1) = await initializeGossipTest()

# Simulate sending an undecodable message
await gossip0.peers[gossip1.switch.peerInfo.peerId].sendEncoded(newSeqWith[byte](30, 1.byte))
await sleepAsync(300.millis)

check getCurrentDisconnections() == disconnections + 1
check currentDisconnections() == disconnections + 1

await stopNodes(nodes)

asyncTest "e2e - GossipSub should rate limit messages with excessive useless data":
let disconnections = getCurrentDisconnections()
asyncTest "e2e - GossipSub should rate limit decodable messages above the size allowed":
let disconnections = currentDisconnections()
let (nodes, gossip0, gossip1) = await initializeGossipTest()

gossip0.broadcast(gossip1.mesh["foobar"], RPCMsg(control: some(ControlMessage(prune: @[
Expand All @@ -998,6 +1000,6 @@ suite "GossipSub":
]))))
await sleepAsync(300.millis)

check getCurrentDisconnections() == disconnections + 1
check currentDisconnections() == disconnections + 1

await stopNodes(nodes)

0 comments on commit d8469d7

Please sign in to comment.