Skip to content

Commit f137169

Browse files
committed
fix: Guard against agent exit outside test func
1 parent f0223ac commit f137169

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cli/portforward_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,15 @@ func runAgent(t *testing.T, client *codersdk.Client, userID uuid.UUID) ([]coders
416416
// Start workspace agent in a goroutine
417417
cmd, root := clitest.New(t, "agent", "--agent-token", agentToken, "--agent-url", client.URL.String())
418418
clitest.SetupConfig(t, client, root)
419+
errC := make(chan error)
419420
agentCtx, agentCancel := context.WithCancel(ctx)
420-
t.Cleanup(agentCancel)
421+
t.Cleanup(func() {
422+
agentCancel()
423+
err := <-errC
424+
require.NoError(t, err)
425+
})
421426
go func() {
422-
err := cmd.ExecuteContext(agentCtx)
427+
errC <- cmd.ExecuteContext(agentCtx)
423428
require.NoError(t, err)
424429
}()
425430

0 commit comments

Comments
 (0)