@cryptotaxi247 / kubo / commits / e3d9e05ec

fix race in TestWantlistClearsOnCancel

fixes #4726 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Feb 21, 2018 at 12:35 UTC e3d9e05ec2fbf7421b0e1c5221333a7ee2664082
1 file changed +9 -3
exchange/bitswap/session_test.go
+9 -3
@@ -8,6 +8,7 @@ import (
8
9 blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil"
10
11 + tu "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
12 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
13 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
14 )
@@ -287,7 +288,7 @@ func TestMultipleSessions(t *testing.T) {
288 }
289
290 func TestWantlistClearsOnCancel(t *testing.T) {
290 - ctx, cancel := context.WithCancel(context.Background())
291 + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
292 defer cancel()
293
294 vnet := getVirtualNetwork()
@@ -314,7 +315,12 @@ func TestWantlistClearsOnCancel(t *testing.T) {
315 }
316 cancel1()
317
317 - if len(a.Exchange.GetWantlist()) > 0 {
318 - t.Fatal("expected empty wantlist")
318 + if err := tu.WaitFor(ctx, func() error {
319 + if len(a.Exchange.GetWantlist()) > 0 {
320 + return fmt.Errorf("expected empty wantlist")
321 + }
322 + return nil
323 + }); err != nil {
324 + t.Fatal(err)
325 }
326 }