fix test raceconditions
@@ -385,7 +385,6 @@ func TestBootstrap(t *testing.T) {
for j := 0; j < nodes[i]; j++ {
wg.Add(1)
go func() {
- time.Sleep(time.Millisecond * time.Duration(rand.Int31n(1000)))
sw := p2pTestInstance(t, cfg)
bufchan <- sw
wg.Done()
@@ -400,8 +399,14 @@ func TestBootstrap(t *testing.T) {
}
- randnode := swarms[rand.Int31n(int32(nodes[i]))-1]
- randnode2 := swarms[rand.Int31n(int32(nodes[i]))-1]
+ randnode := swarms[rand.Int31n(int32(len(swarms)))-1]
+ randnode2 := swarms[rand.Int31n(int32(len(swarms)))-1]
+
+ for (randnode == nil || randnode2 == nil) || randnode.lNode.String() == randnode2.lNode.String() {
+ randnode = swarms[rand.Int31n(int32(len(swarms)))-1]
+ randnode2 = swarms[rand.Int31n(int32(len(swarms)))-1]
+ }
+
randnode.RegisterProtocol(exampleProtocol)
recv := randnode2.RegisterProtocol(exampleProtocol)
