From e3d9e05ec2fbf7421b0e1c5221333a7ee2664082 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 21 Feb 2018 12:35:56 -0800 Subject: [PATCH] fix race in TestWantlistClearsOnCancel fixes #4726 License: MIT Signed-off-by: Steven Allen --- exchange/bitswap/session_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/exchange/bitswap/session_test.go b/exchange/bitswap/session_test.go index 2fe4672b0..75e4da038 100644 --- a/exchange/bitswap/session_test.go +++ b/exchange/bitswap/session_test.go @@ -8,6 +8,7 @@ import ( blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil" + tu "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil" cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid" blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format" ) @@ -287,7 +288,7 @@ func TestMultipleSessions(t *testing.T) { } func TestWantlistClearsOnCancel(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() vnet := getVirtualNetwork() @@ -314,7 +315,12 @@ func TestWantlistClearsOnCancel(t *testing.T) { } cancel1() - if len(a.Exchange.GetWantlist()) > 0 { - t.Fatal("expected empty wantlist") + if err := tu.WaitFor(ctx, func() error { + if len(a.Exchange.GetWantlist()) > 0 { + return fmt.Errorf("expected empty wantlist") + } + return nil + }); err != nil { + t.Fatal(err) } }