Skip to content

Commit

Permalink
Merge pull request #4727 from ipfs/fix/4726
Browse files Browse the repository at this point in the history
fix race in TestWantlistClearsOnCancel
  • Loading branch information
whyrusleeping authored Mar 5, 2018
2 parents 13887ff + e3d9e05 commit c00482a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions exchange/bitswap/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
}

0 comments on commit c00482a

Please sign in to comment.