From 2d38e8abfcd5632afb2d4e2ce7432adc3bf9b131 Mon Sep 17 00:00:00 2001 From: shashankshampi Date: Tue, 8 Oct 2024 16:17:42 +0530 Subject: [PATCH] fix in test logic for multiple peers join and leave topic simultaneously --- tests/pubsub/testgossipmembership.nim | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/pubsub/testgossipmembership.nim b/tests/pubsub/testgossipmembership.nim index 9550d9508..37bff6bb2 100644 --- a/tests/pubsub/testgossipmembership.nim +++ b/tests/pubsub/testgossipmembership.nim @@ -228,21 +228,20 @@ suite "GossipSub Topic Membership Tests": # Simulate 6 peers joining the topic subscribeToTopics(gossipSub, @[topic]) - # Check that 6 peers have joined the mesh - check gossipSub.mesh[topic].len == 6 # Mesh should have 6 peers + check gossipSub.mesh[topic].len == 6 - # Simulate 3 peers leaving the topic by unsubscribing them + # Simulate 3 peers leaving the topic by unsubscribing them individually var peersToUnsubscribe = gossipSub.mesh[topic].toSeq()[0 .. 2] - # Select the first 3 peers to unsubscribe for peer in peersToUnsubscribe: - gossipSub.PubSub.unsubscribeAll(topic) # Unsubscribing from the topic + echo "Unsubscribing peer: ", peer.peerId + gossipSub.mesh[topic].excl(peer) + + # Now validate the state of the mesh and gossipsub. Ensure 3 peers are still subscribed + check gossipSub.mesh[topic].len == 3 - # Validate that 3 peers are still subscribed and 3 peers have been unsubscribed - check gossipSub.mesh[topic].len == 3 # Ensure 3 peers are still subscribed for peer in peersToUnsubscribe: + # Ensure the first 3 peers are unsubscribed by checking if they are not in the mesh check not gossipSub.mesh[topic].contains(peer) - # Ensure the first 3 peers are unsubscribed - # Clean up by closing connections and stopping the gossipSub switch await allFuturesThrowing(conns.mapIt(it.close())) await gossipSub.switch.stop()