@cryptotaxi247 / kubo / commits / 923c082d6

dht: cleaned up dht_test.

TestProversMany still fails

Juan Batiz-Benet committed Dec 24, 2014 at 01:33 UTC 923c082d66234d8d16b2efa38994668afd14e865
1 file changed +42 -27
routing/dht/dht_test.go
+42 -27
@@ -17,6 +17,7 @@ import (
17 // ci "github.com/jbenet/go-ipfs/crypto"
18 inet "github.com/jbenet/go-ipfs/net"
19 peer "github.com/jbenet/go-ipfs/peer"
20 + routing "github.com/jbenet/go-ipfs/routing"
21 u "github.com/jbenet/go-ipfs/util"
22 testutil "github.com/jbenet/go-ipfs/util/testutil"
23 )
@@ -97,14 +98,14 @@ func bootstrap(t *testing.T, ctx context.Context, dhts []*IpfsDHT) {
98
99 rounds := 1
100 for i := 0; i < rounds; i++ {
100 - fmt.Printf("bootstrapping round %d/%d\n", i, rounds)
101 + log.Debugf("bootstrapping round %d/%d\n", i, rounds)
102
103 // tried async. sequential fares much better. compare:
104 // 100 async https://gist.github.com/jbenet/56d12f0578d5f34810b2
105 // 100 sync https://gist.github.com/jbenet/6c59e7c15426e48aaedd
106 // probably because results compound
107 for _, dht := range dhts {
107 - fmt.Printf("bootstrapping round %d/%d -- %s\n", i, rounds, dht.self)
108 + log.Debugf("bootstrapping round %d/%d -- %s\n", i, rounds, dht.self)
109 dht.Bootstrap(ctx, 3)
110 }
111 }
@@ -209,7 +210,7 @@ func TestProvides(t *testing.T) {
210 connect(t, ctx, dhts[1], dhts[3])
211
212 for k, v := range testCaseValues {
212 - t.Logf("adding local values for %s = %s", k, v)
213 + log.Debugf("adding local values for %s = %s", k, v)
214 err := dhts[3].putLocal(k, v)
215 if err != nil {
216 t.Fatal(err)
@@ -225,7 +226,7 @@ func TestProvides(t *testing.T) {
226 }
227
228 for k, _ := range testCaseValues {
228 - t.Logf("announcing provider for %s", k)
229 + log.Debugf("announcing provider for %s", k)
230 if err := dhts[3].Provide(ctx, k); err != nil {
231 t.Fatal(err)
232 }
@@ -238,7 +239,7 @@ func TestProvides(t *testing.T) {
239 for k, _ := range testCaseValues {
240 n = (n + 1) % 3
241
241 - t.Logf("getting providers for %s from %d", k, n)
242 + log.Debugf("getting providers for %s from %d", k, n)
243 ctxT, _ := context.WithTimeout(ctx, time.Second)
244 provchan := dhts[n].FindProvidersAsync(ctxT, k, 1)
245
@@ -259,7 +260,7 @@ func TestProvides(t *testing.T) {
260 func TestBootstrap(t *testing.T) {
261 ctx := context.Background()
262
262 - nDHTs := 10
263 + nDHTs := 15
264 _, _, dhts := setupDHTS(ctx, nDHTs, t)
265 defer func() {
266 for i := 0; i < nDHTs; i++ {
@@ -278,12 +279,23 @@ func TestBootstrap(t *testing.T) {
279 ctxT, _ := context.WithTimeout(ctx, 5*time.Second)
280 bootstrap(t, ctxT, dhts)
281
281 - // the routing tables should be full now. let's inspect them.
282 - t.Logf("checking routing table of %d", nDHTs)
282 + if u.Debug {
283 + // the routing tables should be full now. let's inspect them.
284 + <-time.After(5 * time.Second)
285 + t.Logf("checking routing table of %d", nDHTs)
286 + for _, dht := range dhts {
287 + fmt.Printf("checking routing table of %s\n", dht.self)
288 + dht.routingTable.Print()
289 + fmt.Println("")
290 + }
291 + }
292 +
293 + // test "well-formed-ness" (>= 3 peers in every routing table)
294 for _, dht := range dhts {
284 - fmt.Printf("checking routing table of %s\n", dht.self)
285 - dht.routingTable.Print()
286 - fmt.Println("")
295 + rtlen := dht.routingTable.Size()
296 + if rtlen < 4 {
297 + t.Errorf("routing table for %s only has %d peers", dht.self, rtlen)
298 + }
299 }
300 }
301
@@ -311,13 +323,15 @@ func TestProvidesMany(t *testing.T) {
323 ctxT, _ := context.WithTimeout(ctx, 5*time.Second)
324 bootstrap(t, ctxT, dhts)
325
314 - <-time.After(5 * time.Second)
315 - // the routing tables should be full now. let's inspect them.
316 - t.Logf("checking routing table of %d", nDHTs)
317 - for _, dht := range dhts {
318 - fmt.Printf("checking routing table of %s\n", dht.self)
319 - dht.routingTable.Print()
320 - fmt.Println("")
326 + if u.Debug {
327 + // the routing tables should be full now. let's inspect them.
328 + <-time.After(5 * time.Second)
329 + t.Logf("checking routing table of %d", nDHTs)
330 + for _, dht := range dhts {
331 + fmt.Printf("checking routing table of %s\n", dht.self)
332 + dht.routingTable.Print()
333 + fmt.Println("")
334 + }
335 }
336
337 d := 0
@@ -372,7 +386,7 @@ func TestProvidesMany(t *testing.T) {
386 for k, _ := range testCaseValues {
387 // everyone should be able to find it...
388 for _, dht := range dhts {
375 - t.Logf("getting providers for %s at %s", k, dht.self)
389 + log.Debugf("getting providers for %s at %s", k, dht.self)
390 wg.Add(1)
391 go getProvider(dht, k)
392 }
@@ -384,7 +398,6 @@ func TestProvidesMany(t *testing.T) {
398 close(errchan)
399 }()
400
387 - t.Logf("looking through errors")
401 for err := range errchan {
402 t.Error(err)
403 }
@@ -473,18 +486,20 @@ func TestLayeredGet(t *testing.T) {
486 t.Fatal(err)
487 }
488
476 - time.Sleep(time.Millisecond * 60)
489 + time.Sleep(time.Millisecond * 6)
490
491 + t.Log("interface was changed. GetValue should not use providers.")
492 ctxT, _ := context.WithTimeout(ctx, time.Second)
493 val, err := dhts[0].GetValue(ctxT, u.Key("/v/hello"))
480 - if err != nil {
481 - t.Fatal(err)
494 + if err != routing.ErrNotFound {
495 + t.Error(err)
496 }
483 -
484 - if string(val) != "world" {
485 - t.Fatal("Got incorrect value.")
497 + if string(val) == "world" {
498 + t.Error("should not get value.")
499 + }
500 + if len(val) > 0 && string(val) != "world" {
501 + t.Error("worse, there's a value and its not even the right one.")
502 }
487 -
503 }
504
505 func TestFindPeer(t *testing.T) {