Skip to content

test(scaletest/createworkspaces): fix ctx init in multiple tests #16177

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 1 commit into from
Jan 17, 2025
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
21 changes: 9 additions & 12 deletions scaletest/createworkspaces/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func Test_Runner(t *testing.T) {
t.Run("OK", func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
})
Expand Down Expand Up @@ -109,6 +106,8 @@ func Test_Runner(t *testing.T) {
version = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

ctx := testutil.Context(t, testutil.WaitLong)

closerCh := goEventuallyStartFakeAgent(ctx, t, client, authToken)

const (
Expand Down Expand Up @@ -199,9 +198,6 @@ func Test_Runner(t *testing.T) {
t.Run("CleanupPendingBuild", func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

// need to include our own logger because the provisioner (rightly) drops error logs when we shut down the
// test with a build in progress.
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
Expand Down Expand Up @@ -253,7 +249,9 @@ func Test_Runner(t *testing.T) {
},
})

ctx := testutil.Context(t, testutil.WaitLong)
cancelCtx, cancelFunc := context.WithCancel(ctx)

done := make(chan struct{})
logs := bytes.NewBuffer(nil)
go func() {
Expand Down Expand Up @@ -287,6 +285,8 @@ func Test_Runner(t *testing.T) {
cancelFunc()
<-done

ctx = testutil.Context(t, testutil.WaitLong) // Reset ctx to avoid timeouts.

// When we run the cleanup, it should be canceled
cleanupLogs := bytes.NewBuffer(nil)
cancelCtx, cancelFunc = context.WithCancel(ctx)
Expand Down Expand Up @@ -340,9 +340,6 @@ func Test_Runner(t *testing.T) {
t.Run("NoCleanup", func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
})
Expand Down Expand Up @@ -397,6 +394,7 @@ func Test_Runner(t *testing.T) {
version = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

ctx := testutil.Context(t, testutil.WaitLong)
closeCh := goEventuallyStartFakeAgent(ctx, t, client, authToken)

const (
Expand Down Expand Up @@ -484,9 +482,6 @@ func Test_Runner(t *testing.T) {
t.Run("FailedBuild", func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
Expand Down Expand Up @@ -534,6 +529,8 @@ func Test_Runner(t *testing.T) {
},
})

ctx := testutil.Context(t, testutil.WaitLong)

logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
logsStr := logs.String()
Expand Down
Loading