Improve existing PX test.

This commit is contained in:
Alejandro Cabeza Romero 2024-08-23 18:45:53 +02:00
parent 56419460ae
commit 543c281205
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
1 changed files with 27 additions and 5 deletions

View File

@ -31,7 +31,7 @@ import
protocols/pubsub/rpc/messages, protocols/pubsub/rpc/messages,
] ]
import ../../libp2p/protocols/pubsub/errors as pubsub_errors import ../../libp2p/protocols/pubsub/errors as pubsub_errors
import ../helpers import ../helpers, ../utils/[async]
proc `$`(peer: PubSubPeer): string = proc `$`(peer: PubSubPeer): string =
shortLog(peer) shortLog(peer)
@ -827,7 +827,7 @@ suite "GossipSub":
var var
gossip0 = GossipSub(nodes[0]) gossip0 = GossipSub(nodes[0])
gossip1 = GossipSub(nodes[1]) gossip1 = GossipSub(nodes[1])
gossip2 = GossipSub(nodes[1]) gossip2 = GossipSub(nodes[2])
await subscribeNodes(nodes) await subscribeNodes(nodes)
@ -839,18 +839,40 @@ suite "GossipSub":
if x != y: if x != y:
await waitSub(nodes[x], nodes[y], "foobar") await waitSub(nodes[x], nodes[y], "foobar")
var passed: Future[void] = newFuture[void]() # Setup record handlers for all nodes
var
passed0: Future[void] = newFuture[void]()
passed1: Future[void] = newFuture[void]()
passed2: Future[void] = newFuture[void]()
gossip0.routingRecordsHandler.add( gossip0.routingRecordsHandler.add(
proc(peer: PeerId, tag: string, peers: seq[RoutingRecordsPair]) = proc(peer: PeerId, tag: string, peers: seq[RoutingRecordsPair]) =
check: check:
tag == "foobar" tag == "foobar"
peers.len == 2 peers.len == 2
peers[0].record.isSome() xor peers[1].record.isSome() peers[0].record.isSome() xor peers[1].record.isSome()
passed.complete() passed0.complete()
) )
gossip1.routingRecordsHandler.add(
proc(peer: PeerId, tag: string, peers: seq[RoutingRecordsPair]) =
passed1.complete()
)
gossip2.routingRecordsHandler.add(
proc(peer: PeerId, tag: string, peers: seq[RoutingRecordsPair]) =
check:
tag == "foobar"
peers.len == 2
peers[0].record.isSome() xor peers[1].record.isSome()
passed2.complete()
)
# Unsubscribe from the topic
nodes[1].unsubscribe("foobar", handler) nodes[1].unsubscribe("foobar", handler)
await passed.wait(5.seconds) # Then verify what nodes receive the PX
check:
(await passed0.waitForResult()).isOk
not (await passed1.waitForResult()).isOk
(await passed2.waitForResult()).isOk
await allFuturesThrowing( await allFuturesThrowing(
nodes[0].switch.stop(), nodes[1].switch.stop(), nodes[2].switch.stop() nodes[0].switch.stop(), nodes[1].switch.stop(), nodes[2].switch.stop()