bitswap_test: make racy test less racy
fixes #4108 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Jul 30, 2017 at 23:40 UTC
67c572e75070b577fff5914fb41e2cc4d8ff9edc
1 file changed
+11
-7
exchange/bitswap/bitswap_test.go
+11
-7
@@ -21,6 +21,7 @@ import (
21
22
cid "gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
23
p2ptestutil "gx/ipfs/QmZG4W8GR9FpC4z69Vab9ENtEoxKjDnTym5oa7Q3Yr7P4o/go-libp2p-netutil"
24
+ tu "gx/ipfs/QmZJD56ZWLViJAVkvLc7xbbDerHzUMLr2X4fLRYfbxZWDN/go-testutil"
25
)
26
27
// FIXME the tests are really sensitive to the network delay. fix them to work
@@ -332,13 +333,16 @@ func TestBasicBitswap(t *testing.T) {
333
t.Fatal(err)
334
}
335
335
- time.Sleep(time.Millisecond * 25)
336
- wl := instances[2].Exchange.WantlistForPeer(instances[1].Peer)
337
- if len(wl) != 0 {
338
- t.Fatal("should have no items in other peers wantlist")
339
- }
340
- if len(instances[1].Exchange.GetWantlist()) != 0 {
341
- t.Fatal("shouldnt have anything in wantlist")
336
+ if err = tu.WaitFor(ctx, func() error {
337
+ if len(instances[2].Exchange.WantlistForPeer(instances[1].Peer)) != 0 {
338
+ return fmt.Errorf("should have no items in other peers wantlist")
339
+ }
340
+ if len(instances[1].Exchange.GetWantlist()) != 0 {
341
+ return fmt.Errorf("shouldnt have anything in wantlist")
342
+ }
343
+ return nil
344
+ }); err != nil {
345
+ t.Fatal(err)
346
}
347
348
st0, err := instances[0].Exchange.Stat()