Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail fast in tests that use a waitgroup Wait() #450

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions storagemarket/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestMakeDealOffline(t *testing.T) {

h.WaitForClientEvent(&wg, storagemarket.ClientEventDataTransferComplete)
h.WaitForProviderEvent(&wg, storagemarket.ProviderEventDataRequested)
wg.Wait()
waitGroupWait(ctx, &wg)

cd, err := h.Client.GetLocalDeal(ctx, proposalCid)
assert.NoError(t, err)
Expand All @@ -230,7 +230,7 @@ func TestMakeDealOffline(t *testing.T) {

h.WaitForClientEvent(&wg, storagemarket.ClientEventDealExpired)
h.WaitForProviderEvent(&wg, storagemarket.ProviderEventDealExpired)
wg.Wait()
waitGroupWait(ctx, &wg)

cd, err = h.Client.GetLocalDeal(ctx, proposalCid)
assert.NoError(t, err)
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestMakeDealNonBlocking(t *testing.T) {
wg := sync.WaitGroup{}
h.WaitForClientEvent(&wg, storagemarket.ClientEventDataTransferComplete)
h.WaitForProviderEvent(&wg, storagemarket.ProviderEventFundingInitiated)
wg.Wait()
waitGroupWait(ctx, &wg)

cd, err := h.Client.GetLocalDeal(ctx, result.ProposalCid)
assert.NoError(t, err)
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestRestartOnlyProviderDataTransfer(t *testing.T) {
proposalCid := result.ProposalCid
t.Log("storage deal proposed")

wg.Wait()
waitGroupWait(ctx, &wg)
t.Log("provider has been shutdown the first time")

// Assert client state
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestRestartOnlyProviderDataTransfer(t *testing.T) {
require.NotNil(t, conn)
shared_testutil.StartAndWaitForReady(ctx, t, h.Provider)
t.Log("------- provider has been restarted---------")
expireWg.Wait()
waitGroupWait(ctx, &expireWg)
t.Log("---------- finished waiting for expected events-------")

cd, err = client.GetLocalDeal(ctx, proposalCid)
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestRestartClient(t *testing.T) {
proposalCid := result.ProposalCid
t.Log("storage deal proposed")

wg.Wait()
waitGroupWait(ctx, &wg)
t.Log("both client and provider have been shutdown the first time")

cd, err := h.Client.GetLocalDeal(ctx, proposalCid)
Expand Down Expand Up @@ -547,7 +547,7 @@ func TestRestartClient(t *testing.T) {
shared_testutil.StartAndWaitForReady(ctx, t, h.Provider)
shared_testutil.StartAndWaitForReady(ctx, t, h.Client)
t.Log("------- client and provider have been restarted---------")
wg.Wait()
waitGroupWait(ctx, &wg)
t.Log("---------- finished waiting for expected events-------")

cd, err = h.Client.GetLocalDeal(ctx, proposalCid)
Expand All @@ -563,3 +563,17 @@ func TestRestartClient(t *testing.T) {
})
}
}

// waitGroupWait calls wg.Wait while respecting context cancellation
func waitGroupWait(ctx context.Context, wg *sync.WaitGroup) {
done := make(chan struct{})
go func() {
wg.Wait()
close(done)
}()

select {
case <-ctx.Done():
case <-done:
}
}