Skip to content

Commit 9e0eb5f

Browse files
committed
fixup! chore(scaletest/createworkspaces): address context usage
1 parent 5db2d84 commit 9e0eb5f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

scaletest/createworkspaces/run_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,23 +249,23 @@ func Test_Runner(t *testing.T) {
249249
},
250250
})
251251

252-
ctx := testutil.Context(t, testutil.WaitLong)
253-
cancelCtx, cancelFunc := context.WithCancel(ctx)
252+
runnerCtx, runnerCancel := context.WithTimeout(context.Background(), testutil.WaitLong)
254253

255254
done := make(chan struct{})
256255
logs := bytes.NewBuffer(nil)
257256
go func() {
258-
err := runner.Run(cancelCtx, "1", logs)
257+
err := runner.Run(runnerCtx, "1", logs)
259258
logsStr := logs.String()
260259
t.Log("Runner logs:\n\n" + logsStr)
261260
require.ErrorIs(t, err, context.Canceled)
262261
close(done)
263262
}()
264263

265264
// Wait for the workspace build job to be picked up.
265+
checkJobStartedCtx := testutil.Context(t, testutil.WaitLong)
266266
jobCh := make(chan codersdk.ProvisionerJob, 1)
267267
require.Eventually(t, func() bool {
268-
workspaces, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{})
268+
workspaces, err := client.Workspaces(checkJobStartedCtx, codersdk.WorkspaceFilter{})
269269
if err != nil {
270270
return false
271271
}
@@ -289,7 +289,7 @@ func Test_Runner(t *testing.T) {
289289
}, testutil.WaitLong, testutil.IntervalSlow)
290290

291291
t.Log("canceling scaletest workspace creation")
292-
cancelFunc()
292+
runnerCancel()
293293
<-done
294294
t.Log("canceled scaletest workspace creation")
295295
// Ensure we have a job to interrogate
@@ -299,17 +299,18 @@ func Test_Runner(t *testing.T) {
299299
// When we run the cleanup, it should be canceled
300300
cleanupLogs := bytes.NewBuffer(nil)
301301
// Reset ctx to avoid timeouts.
302-
cancelCtx, cancelFunc = context.WithTimeout(context.Background(), testutil.WaitLong)
302+
cleanupCtx, cleanupCancel := context.WithTimeout(context.Background(), testutil.WaitLong)
303303
done = make(chan struct{})
304304
go func() {
305305
// This will return an error as the "delete" operation will never complete.
306-
_ = runner.Cleanup(cancelCtx, "1", cleanupLogs)
306+
_ = runner.Cleanup(cleanupCtx, "1", cleanupLogs)
307307
close(done)
308308
}()
309309

310310
// Ensure the job has been marked as canceled
311+
checkJobCanceledCtx := testutil.Context(t, testutil.WaitLong)
311312
require.Eventually(t, func() bool {
312-
pj, err := client.OrganizationProvisionerJob(ctx, runningJob.OrganizationID, runningJob.ID)
313+
pj, err := client.OrganizationProvisionerJob(checkJobCanceledCtx, runningJob.OrganizationID, runningJob.ID)
313314
if !assert.NoError(t, err) {
314315
return false
315316
}
@@ -324,7 +325,7 @@ func Test_Runner(t *testing.T) {
324325

325326
return true
326327
}, testutil.WaitLong, testutil.IntervalSlow)
327-
cancelFunc()
328+
cleanupCancel()
328329
<-done
329330
cleanupLogsStr := cleanupLogs.String()
330331
require.Contains(t, cleanupLogsStr, "canceling workspace build")

0 commit comments

Comments
 (0)