dht/bootstrap/test: longer timeout, less bias
Juan Batiz-Benet committed
Jan 5, 2015 at 07:19 UTC
1d9977c8504e316026f899b7fcbac012411b6123
1 file changed
+7
-2
routing/dht/dht_test.go
+7
-2
@@ -3,6 +3,7 @@ package dht
3
import (
4
"bytes"
5
"fmt"
6
+ "math/rand"
7
"sort"
8
"sync"
9
"testing"
@@ -76,6 +77,7 @@ func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) {
77
ctx, cancel := context.WithCancel(ctx)
78
79
rounds := 1
80
+
81
for i := 0; i < rounds; i++ {
82
log.Debugf("bootstrapping round %d/%d\n", i, rounds)
83
@@ -83,7 +85,10 @@ func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) {
85
// 100 async https://gist.github.com/jbenet/56d12f0578d5f34810b2
86
// 100 sync https://gist.github.com/jbenet/6c59e7c15426e48aaedd
87
// probably because results compound
86
- for _, dht := range dhts {
88
+
89
+ start := rand.Intn(len(dhts)) // randomize to decrease bias.
90
+ for i := range dhts {
91
+ dht := dhts[(start+i)%len(dhts)]
92
log.Debugf("bootstrapping round %d/%d -- %s\n", i, rounds, dht.self)
93
dht.Bootstrap(ctx, 3)
94
}
@@ -309,7 +314,7 @@ func TestProvidesMany(t *testing.T) {
314
315
<-time.After(100 * time.Millisecond)
316
t.Logf("bootstrapping them so they find each other", nDHTs)
312
- ctxT, _ := context.WithTimeout(ctx, 5*time.Second)
317
+ ctxT, _ := context.WithTimeout(ctx, 20*time.Second)
318
bootstrap(t, ctxT, dhts)
319
320
if u.Debug {