From caffc3bf2cbfab6a05aa8f281601791720bd0a36 Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 23 Apr 2020 12:41:53 +0300 Subject: [PATCH] make star topology tests more reliable probabilities are such that they occasionally fail --- gossipsub_test.go | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/gossipsub_test.go b/gossipsub_test.go index 83fd588..ad85859 100644 --- a/gossipsub_test.go +++ b/gossipsub_test.go @@ -942,6 +942,18 @@ func TestGossipsubTreeTopology(t *testing.T) { // this tests overlay bootstrapping through px in Gossipsub v1.1 // we start with a star topology and rely on px through prune to build the mesh func TestGossipsubStarTopology(t *testing.T) { + originalGossipSubD := GossipSubD + GossipSubD = 4 + originalGossipSubDhi := GossipSubDhi + GossipSubDhi = GossipSubD + 1 + originalGossipSubDlo := GossipSubDlo + GossipSubDlo = GossipSubD - 1 + defer func() { + GossipSubD = originalGossipSubD + GossipSubDhi = originalGossipSubDhi + GossipSubDlo = originalGossipSubDlo + }() + ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -965,6 +977,8 @@ func TestGossipsubStarTopology(t *testing.T) { connect(t, hosts[0], hosts[i]) } + time.Sleep(time.Second) + // build the mesh var subs []*Subscription for _, ps := range psubs { @@ -979,9 +993,9 @@ func TestGossipsubStarTopology(t *testing.T) { time.Sleep(10 * time.Second) // check that all peers have > 1 connection - for _, h := range hosts { + for i, h := range hosts { if len(h.Network().Conns()) == 1 { - t.Error("peer has ony a single connection") + t.Errorf("peer %d has ony a single connection", i) } } @@ -1000,6 +1014,18 @@ func TestGossipsubStarTopology(t *testing.T) { // exchanged in signed peer records. // we start with a star topology and rely on px through prune to build the mesh func TestGossipsubStarTopologyWithSignedPeerRecords(t *testing.T) { + originalGossipSubD := GossipSubD + GossipSubD = 4 + originalGossipSubDhi := GossipSubDhi + GossipSubDhi = GossipSubD + 1 + originalGossipSubDlo := GossipSubDlo + GossipSubDlo = GossipSubD - 1 + defer func() { + GossipSubD = originalGossipSubD + GossipSubDhi = originalGossipSubDhi + GossipSubDlo = originalGossipSubDlo + }() + ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -1035,6 +1061,8 @@ func TestGossipsubStarTopologyWithSignedPeerRecords(t *testing.T) { connect(t, hosts[0], hosts[i]) } + time.Sleep(time.Second) + // build the mesh var subs []*Subscription for _, ps := range psubs { @@ -1049,9 +1077,9 @@ func TestGossipsubStarTopologyWithSignedPeerRecords(t *testing.T) { time.Sleep(10 * time.Second) // check that all peers have > 1 connection - for _, h := range hosts { + for i, h := range hosts { if len(h.Network().Conns()) == 1 { - t.Error("peer has ony a single connection") + t.Errorf("peer %d has ony a single connection", i) } }