Skip to content

fix: Fix cleanup in test helpers, prefer defer in tests #3113

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 7 commits into from
Jul 25, 2022
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
Prev Previous commit
Next Next commit
fix: Revert bad change
  • Loading branch information
mafredri committed Jul 25, 2022
commit d263af2d9246efd81e8276426647f65a93d7a266
9 changes: 5 additions & 4 deletions cli/portforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ func runAgent(t *testing.T, client *codersdk.Client, userID uuid.UUID) ([]coders
clitest.SetupConfig(t, client, root)
errC := make(chan error)
agentCtx, agentCancel := context.WithCancel(ctx)
defer agentCancel()
t.Cleanup(func() {
agentCancel()
err := <-errC
require.NoError(t, err)
})
go func() {
errC <- cmd.ExecuteContext(agentCtx)
}()
Expand All @@ -403,9 +407,6 @@ func runAgent(t *testing.T, client *codersdk.Client, userID uuid.UUID) ([]coders
resources, err := client.WorkspaceResourcesByBuild(context.Background(), workspace.LatestBuild.ID)
require.NoError(t, err)

err := <-errC
require.NoError(t, err)

return resources, workspace
}

Expand Down