From bc1d8965051db9de279375b0273aa6de5574660b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 30 Jul 2017 23:40:25 -0700 Subject: [PATCH] bitswap_test: make racy test less racy fixes #4108 License: MIT Signed-off-by: Steven Allen --- exchange/bitswap/bitswap_test.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/exchange/bitswap/bitswap_test.go b/exchange/bitswap/bitswap_test.go index 316eda279b83..ba3cbdc312f1 100644 --- a/exchange/bitswap/bitswap_test.go +++ b/exchange/bitswap/bitswap_test.go @@ -332,13 +332,26 @@ func TestBasicBitswap(t *testing.T) { t.Fatal(err) } - time.Sleep(time.Millisecond * 25) - wl := instances[2].Exchange.WantlistForPeer(instances[1].Peer) - if len(wl) != 0 { - t.Fatal("should have no items in other peers wantlist") + check := func() error { + if len(instances[2].Exchange.WantlistForPeer(instances[1].Peer)) != 0 { + return fmt.Errorf("should have no items in other peers wantlist") + } + + if len(instances[1].Exchange.GetWantlist()) != 0 { + return fmt.Errorf("shouldnt have anything in wantlist") + } + return nil } - if len(instances[1].Exchange.GetWantlist()) != 0 { - t.Fatal("shouldnt have anything in wantlist") + + for { + time.Sleep(time.Millisecond * 10) + err := check() + if err == nil { + break + } + if ctx.Err() != nil { + t.Fatal(err) + } } st0, err := instances[0].Exchange.Stat()