diff --git a/tests/pubsub/testgossipsub.nim b/tests/pubsub/testgossipsub.nim index 628506f..3a08ad5 100644 --- a/tests/pubsub/testgossipsub.nim +++ b/tests/pubsub/testgossipsub.nim @@ -614,7 +614,7 @@ suite "GossipSub": nodesFut = nodes.mapIt(it.switch.start()) await allFuturesThrowing(nodes.mapIt(it.start())) - await subscribeNodes(nodes) + await subscribeSparseNodes(nodes) var seen: Table[string, int] var seenFut = newFuture[void]() @@ -769,3 +769,101 @@ suite "GossipSub": ) await allFuturesThrowing(nodesFut.concat()) + + asyncTest "GossipsSub peers disconnections mechanics": + var runs = 10 + + let + nodes = generateNodes(runs, gossip = true, triggerSelf = true) + nodesFut = nodes.mapIt(it.switch.start()) + + await allFuturesThrowing(nodes.mapIt(it.start())) + await subscribeNodes(nodes) + + var seen: Table[string, int] + var seenFut = newFuture[void]() + for i in 0..= runs: + seenFut.complete() + + dialer.subscribe("foobar", handler) + await waitSub(nodes[0], dialer, "foobar") + + # ensure peer stats are stored properly and kept properly + check: + GossipSub(nodes[0]).peerStats.len == runs - 1 # minus self + + tryPublish await wait(nodes[0].publish("foobar", + toBytes("from node " & + $nodes[0].peerInfo.peerId)), + 1.minutes), 1, 5.seconds + + await wait(seenFut, 5.minutes) + check: seen.len >= runs + for k, v in seen.pairs: + check: v >= 1 + + for node in nodes: + var gossip = GossipSub(node) + check: + "foobar" in gossip.gossipsub + gossip.fanout.len == 0 + gossip.mesh["foobar"].len > 0 + + # Removing some subscriptions + + for i in 0..