Skip to content

Commit ea8cd55

Browse files
authored
test(scaletest/createworkspaces): fix ctx init in multiple tests (#16177)
1 parent f32f7c6 commit ea8cd55

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

scaletest/createworkspaces/run_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ func Test_Runner(t *testing.T) {
5252
t.Run("OK", func(t *testing.T) {
5353
t.Parallel()
5454

55-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
56-
defer cancel()
57-
5855
client := coderdtest.New(t, &coderdtest.Options{
5956
IncludeProvisionerDaemon: true,
6057
})
@@ -109,6 +106,8 @@ func Test_Runner(t *testing.T) {
109106
version = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
110107
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
111108

109+
ctx := testutil.Context(t, testutil.WaitLong)
110+
112111
closerCh := goEventuallyStartFakeAgent(ctx, t, client, authToken)
113112

114113
const (
@@ -199,9 +198,6 @@ func Test_Runner(t *testing.T) {
199198
t.Run("CleanupPendingBuild", func(t *testing.T) {
200199
t.Parallel()
201200

202-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
203-
defer cancel()
204-
205201
// need to include our own logger because the provisioner (rightly) drops error logs when we shut down the
206202
// test with a build in progress.
207203
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
@@ -253,7 +249,9 @@ func Test_Runner(t *testing.T) {
253249
},
254250
})
255251

252+
ctx := testutil.Context(t, testutil.WaitLong)
256253
cancelCtx, cancelFunc := context.WithCancel(ctx)
254+
257255
done := make(chan struct{})
258256
logs := bytes.NewBuffer(nil)
259257
go func() {
@@ -287,6 +285,8 @@ func Test_Runner(t *testing.T) {
287285
cancelFunc()
288286
<-done
289287

288+
ctx = testutil.Context(t, testutil.WaitLong) // Reset ctx to avoid timeouts.
289+
290290
// When we run the cleanup, it should be canceled
291291
cleanupLogs := bytes.NewBuffer(nil)
292292
cancelCtx, cancelFunc = context.WithCancel(ctx)
@@ -340,9 +340,6 @@ func Test_Runner(t *testing.T) {
340340
t.Run("NoCleanup", func(t *testing.T) {
341341
t.Parallel()
342342

343-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
344-
defer cancel()
345-
346343
client := coderdtest.New(t, &coderdtest.Options{
347344
IncludeProvisionerDaemon: true,
348345
})
@@ -397,6 +394,7 @@ func Test_Runner(t *testing.T) {
397394
version = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
398395
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
399396

397+
ctx := testutil.Context(t, testutil.WaitLong)
400398
closeCh := goEventuallyStartFakeAgent(ctx, t, client, authToken)
401399

402400
const (
@@ -484,9 +482,6 @@ func Test_Runner(t *testing.T) {
484482
t.Run("FailedBuild", func(t *testing.T) {
485483
t.Parallel()
486484

487-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
488-
defer cancel()
489-
490485
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
491486
client := coderdtest.New(t, &coderdtest.Options{
492487
IncludeProvisionerDaemon: true,
@@ -534,6 +529,8 @@ func Test_Runner(t *testing.T) {
534529
},
535530
})
536531

532+
ctx := testutil.Context(t, testutil.WaitLong)
533+
537534
logs := bytes.NewBuffer(nil)
538535
err := runner.Run(ctx, "1", logs)
539536
logsStr := logs.String()

0 commit comments

Comments
 (0)