bootstrap test
Juan Batiz-Benet committed
Dec 23, 2014 at 19:05 UTC
f8c523fc3bc2e4e4b04fa753270e2607ac4e3ac9
1 file changed
+44
-4
routing/dht/dht_test.go
+44
-4
@@ -91,6 +91,18 @@ func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) {
91
}
92
}
93
94
+func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) {
95
+ var wg sync.WaitGroup
96
+ for _, dht := range dhts {
97
+ wg.Add(1)
98
+ go func() {
99
+ defer wg.Done()
100
+ dht.Bootstrap(ctx)
101
+ }()
102
+ }
103
+ wg.Wait()
104
+}
105
+
106
func TestPing(t *testing.T) {
107
// t.Skip("skipping test to debug another")
108
ctx := context.Background()
@@ -235,8 +247,38 @@ func TestProvides(t *testing.T) {
247
}
248
}
249
250
+func TestBootstrap(t *testing.T) {
251
+ ctx := context.Background()
252
+
253
+ nDHTs := 40
254
+ _, _, dhts := setupDHTS(ctx, nDHTs, t)
255
+ defer func() {
256
+ for i := 0; i < nDHTs; i++ {
257
+ dhts[i].Close()
258
+ defer dhts[i].network.Close()
259
+ }
260
+ }()
261
+
262
+ t.Logf("connecting %d dhts in a ring", nDHTs)
263
+ for i := 0; i < nDHTs; i++ {
264
+ connect(t, ctx, dhts[i], dhts[(i+1)%len(dhts)])
265
+ }
266
+
267
+ t.Logf("bootstrapping them so they find each other", nDHTs)
268
+ bootstrap(t, ctx, dhts)
269
+
270
+ // the routing tables should be full now. let's inspect them.
271
+ t.Logf("checking routing table of %d", nDHTs)
272
+ for _, dht := range dhts {
273
+ fmt.Printf("checking routing table of %s\n", dht.self)
274
+ dht.routingTable.Print()
275
+ fmt.Println("")
276
+ }
277
+}
278
+
279
func TestProvidesMany(t *testing.T) {
280
t.Skip("this test doesn't work")
281
+ // t.Skip("skipping test to debug another")
282
ctx := context.Background()
283
284
nDHTs := 40
@@ -253,10 +295,8 @@ func TestProvidesMany(t *testing.T) {
295
connect(t, ctx, dhts[i], dhts[(i+1)%len(dhts)])
296
}
297
256
- // t.Logf("bootstrapping them so they find each other", nDHTs)
257
- // for _, dht := range dhts {
258
- // bootstrap(t, ctx, dht)
259
- // }
298
+ t.Logf("bootstrapping them so they find each other", nDHTs)
299
+ bootstrap(t, ctx, dhts)
300
301
d := 0
302
for k, v := range testCaseValues {