From c3af7659b09385aacace2941edfceed15abc6231 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Mon, 20 Jul 2020 15:55:00 +0900 Subject: [PATCH] Add more checks and fix some issues in gossip tests (#281) --- tests/pubsub/testgossipsub.nim | 62 +++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/tests/pubsub/testgossipsub.nim b/tests/pubsub/testgossipsub.nim index 5e7a80c1e..651aa2273 100644 --- a/tests/pubsub/testgossipsub.nim +++ b/tests/pubsub/testgossipsub.nim @@ -87,7 +87,15 @@ suite "GossipSub": nodes[1].addValidator("foobar", validator) tryPublish await nodes[0].publish("foobar", "Hello!".toBytes()), 1 + result = (await validatorFut) and (await handlerFut) + + let gossip1 = GossipSub(nodes[0].pubSub.get()) + let gossip2 = GossipSub(nodes[1].pubSub.get()) + check: + gossip1.mesh["foobar"].len == 1 and "foobar" notin gossip1.fanout + gossip2.mesh["foobar"].len == 1 and "foobar" notin gossip2.fanout + await allFuturesThrowing( nodes[0].stop(), nodes[1].stop()) @@ -108,6 +116,7 @@ suite "GossipSub": await subscribeNodes(nodes) + await nodes[0].subscribe("foobar", handler) await nodes[1].subscribe("foobar", handler) var validatorFut = newFuture[bool]() @@ -121,6 +130,13 @@ suite "GossipSub": tryPublish await nodes[0].publish("foobar", "Hello!".toBytes()), 1 result = await validatorFut + + let gossip1 = GossipSub(nodes[0].pubSub.get()) + let gossip2 = GossipSub(nodes[1].pubSub.get()) + check: + gossip1.mesh["foobar"].len == 1 and "foobar" notin gossip1.fanout + gossip2.mesh["foobar"].len == 1 and "foobar" notin gossip2.fanout + await allFuturesThrowing( nodes[0].stop(), nodes[1].stop()) @@ -161,6 +177,15 @@ suite "GossipSub": tryPublish await nodes[0].publish("bar", "Hello!".toBytes()), 1 result = ((await passed) and (await failed) and (await handlerFut)) + + let gossip1 = GossipSub(nodes[0].pubSub.get()) + let gossip2 = GossipSub(nodes[1].pubSub.get()) + check: + "foo" notin gossip1.mesh and gossip1.fanout["foo"].len == 1 + "foo" notin gossip2.mesh and "foo" notin gossip2.fanout + "bar" notin gossip1.mesh and gossip1.fanout["bar"].len == 1 + "bar" notin gossip2.mesh and "bar" notin gossip2.fanout + await allFuturesThrowing( nodes[0].stop(), nodes[1].stop()) @@ -281,10 +306,13 @@ suite "GossipSub": tryPublish await nodes[0].publish("foobar", "Hello!".toBytes()), 1 - var gossipSub1: GossipSub = GossipSub(nodes[0].pubSub.get()) + var gossip1: GossipSub = GossipSub(nodes[0].pubSub.get()) + var gossip2: GossipSub = GossipSub(nodes[1].pubSub.get()) check: - "foobar" in gossipSub1.gossipsub + "foobar" in gossip1.gossipsub + gossip1.fanout.hasPeerID("foobar", gossip2.peerInfo.id) + not gossip1.mesh.hasPeerID("foobar", gossip2.peerInfo.id) await passed.wait(2.seconds) @@ -314,6 +342,7 @@ suite "GossipSub": await subscribeNodes(nodes) + await nodes[0].subscribe("foobar", handler) await nodes[1].subscribe("foobar", handler) await waitSub(nodes[0], nodes[1], "foobar") @@ -321,6 +350,17 @@ suite "GossipSub": result = await passed + var gossip1: GossipSub = GossipSub(nodes[0].pubSub.get()) + var gossip2: GossipSub = GossipSub(nodes[1].pubSub.get()) + + check: + "foobar" in gossip1.gossipsub + "foobar" in gossip2.gossipsub + gossip1.mesh.hasPeerID("foobar", gossip2.peerInfo.id) + not gossip1.fanout.hasPeerID("foobar", gossip2.peerInfo.id) + gossip2.mesh.hasPeerID("foobar", gossip1.peerInfo.id) + not gossip2.fanout.hasPeerID("foobar", gossip1.peerInfo.id) + await nodes[0].stop() await nodes[1].stop() await allFuturesThrowing(wait) @@ -371,6 +411,13 @@ suite "GossipSub": for k, v in seen.pairs: check: v >= 1 + for node in nodes: + var gossip: GossipSub = GossipSub(node.pubSub.get()) + check: + "foobar" in gossip.gossipsub + gossip.fanout.len == 0 + gossip.mesh["foobar"].len > 0 + await allFuturesThrowing(nodes.mapIt(it.stop())) await allFuturesThrowing(awaitters) result = true @@ -390,7 +437,7 @@ suite "GossipSub": secureManagers = [SecureProtocol.Secio]) awaitters.add((await nodes[i].start())) - await subscribeSparseNodes(nodes, 1) # TODO: figure out better sparse mesh + await subscribeSparseNodes(nodes) var seen: Table[string, int] var subs: seq[Future[void]] @@ -415,12 +462,19 @@ suite "GossipSub": tryPublish await wait(nodes[0].publish("foobar", cast[seq[byte]]("from node " & nodes[1].peerInfo.id)), - 1.minutes), 3, 5.seconds + 1.minutes), 2, 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 = GossipSub(node.pubSub.get()) + check: + "foobar" in gossip.gossipsub + gossip.fanout.len == 0 + gossip.mesh["foobar"].len > 0 await allFuturesThrowing(nodes.mapIt(it.stop())) await allFuturesThrowing(awaitters)