Skip to content

fix(cli/clitest): race between Start/StartWithWaiter cleanup order #7232

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

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from 1 commit
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
Next Next commit
fix(cli/clitest): race between Start/StartWithWaiter cleanup order
  • Loading branch information
coadler committed Apr 20, 2023
commit e9c08681def54745d34c72682181e6915f7abd82
13 changes: 8 additions & 5 deletions cli/clitest/clitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,23 @@ func Start(t *testing.T, inv *clibase.Invocation) {
t.Helper()

closeCh := make(chan struct{})
// StartWithWaiter adds its own `t.Cleanup`, so we need to be sure it's added
// before ours.
waiter := StartWithWaiter(t, inv)
t.Cleanup(func() {
<-closeCh
})

go func() {
defer close(closeCh)
err := StartWithWaiter(t, inv).Wait()
err := waiter.Wait()
switch {
case errors.Is(err, context.Canceled):
return
default:
assert.NoError(t, err)
}
}()

t.Cleanup(func() {
<-closeCh
})
}

// Run runs the command and asserts that there is no error.
Expand Down