diff --git a/session_test.go b/session_test.go index 2fe4672b06c67d126adb138fc6c631a5b693376b..75e4da0382265b9949f9ea8695298a68551a2744 100644 --- a/session_test.go +++ b/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) } }