This commit is contained in:
shashankshampi 2024-10-06 01:45:13 +05:30
parent e10e4d058b
commit 89473da8bc

View File

@ -15,18 +15,14 @@ import ../../libp2p/builders
import ../../libp2p/errors
import ../../libp2p/crypto/crypto
import ../../libp2p/stream/bufferstream
import ../../libp2p/protocols/pubsub/[pubsub, gossipsub, mcache, mcache, peertable]
import ../../libp2p/protocols/pubsub/rpc/[message, messages]
import ../../libp2p/switch
import ../../libp2p/muxers/muxer
import ../../libp2p/protocols/pubsub/rpc/protobuf
import utils
import chronos
import unittest2
import ../helpers
import chronos/ratelimit
import metrics
import chronicles
import ../../libp2p/protocols/pubsub/errors as pubsub_errors
import ../helpers
proc noop(data: seq[byte]) {.async: (raises: [CancelledError, LPStreamError]).} =
@ -87,28 +83,21 @@ suite "GossipSub Topic Membership Tests":
let topic = "test-topic"
let (gossipSub, conns) = setupGossipSub(topic, 5)
# Check if the topic is added to gossipsub and the peers list is not empty
check gossipSub.gossipsub[topic].len() > 0
# Subscribe to the topic
subscribeToTopics(gossipSub, @[topic])
# Check if the topic is present in the list of subscribed topics
check gossipSub.topics.contains(topic)
# Check if the topic is added to gossipsub and the peers list is not empty
check gossipSub.gossipsub[topic].len() > 0
# Close all peer connections and verify that they are properly cleaned up
await allFuturesThrowing(conns.mapIt(it.close()))
# Stop the gossipSub switch and wait for it to stop completely
await gossipSub.switch.stop()
# Verify that connections have been closed and cleaned up after shutdown
for peer in gossipSub.peers.values:
check peer.sendConn == nil or peer.sendConn.closed()
# Ensure that the topic is removed from the mesh after stopping
check gossipSub.mesh[topic].len() == 0
# Simulate an UNSUBSCRIBE to the topic and check if the topic is removed from the relevant data structures but remains in gossipsub
asyncTest "handle UNSUBSCRIBE to the topic":
let topic = "test-topic"