@@ -249,23 +249,23 @@ func Test_Runner(t *testing.T) {
249
249
},
250
250
})
251
251
252
- ctx := testutil .Context (t , testutil .WaitLong )
253
- cancelCtx , cancelFunc := context .WithCancel (ctx )
252
+ runnerCtx , runnerCancel := context .WithTimeout (context .Background (), testutil .WaitLong )
254
253
255
254
done := make (chan struct {})
256
255
logs := bytes .NewBuffer (nil )
257
256
go func () {
258
- err := runner .Run (cancelCtx , "1" , logs )
257
+ err := runner .Run (runnerCtx , "1" , logs )
259
258
logsStr := logs .String ()
260
259
t .Log ("Runner logs:\n \n " + logsStr )
261
260
require .ErrorIs (t , err , context .Canceled )
262
261
close (done )
263
262
}()
264
263
265
264
// Wait for the workspace build job to be picked up.
265
+ checkJobStartedCtx := testutil .Context (t , testutil .WaitLong )
266
266
jobCh := make (chan codersdk.ProvisionerJob , 1 )
267
267
require .Eventually (t , func () bool {
268
- workspaces , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {})
268
+ workspaces , err := client .Workspaces (checkJobStartedCtx , codersdk.WorkspaceFilter {})
269
269
if err != nil {
270
270
return false
271
271
}
@@ -289,7 +289,7 @@ func Test_Runner(t *testing.T) {
289
289
}, testutil .WaitLong , testutil .IntervalSlow )
290
290
291
291
t .Log ("canceling scaletest workspace creation" )
292
- cancelFunc ()
292
+ runnerCancel ()
293
293
<- done
294
294
t .Log ("canceled scaletest workspace creation" )
295
295
// Ensure we have a job to interrogate
@@ -299,17 +299,18 @@ func Test_Runner(t *testing.T) {
299
299
// When we run the cleanup, it should be canceled
300
300
cleanupLogs := bytes .NewBuffer (nil )
301
301
// Reset ctx to avoid timeouts.
302
- cancelCtx , cancelFunc = context .WithTimeout (context .Background (), testutil .WaitLong )
302
+ cleanupCtx , cleanupCancel : = context .WithTimeout (context .Background (), testutil .WaitLong )
303
303
done = make (chan struct {})
304
304
go func () {
305
305
// This will return an error as the "delete" operation will never complete.
306
- _ = runner .Cleanup (cancelCtx , "1" , cleanupLogs )
306
+ _ = runner .Cleanup (cleanupCtx , "1" , cleanupLogs )
307
307
close (done )
308
308
}()
309
309
310
310
// Ensure the job has been marked as canceled
311
+ checkJobCanceledCtx := testutil .Context (t , testutil .WaitLong )
311
312
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 )
313
314
if ! assert .NoError (t , err ) {
314
315
return false
315
316
}
@@ -324,7 +325,7 @@ func Test_Runner(t *testing.T) {
324
325
325
326
return true
326
327
}, testutil .WaitLong , testutil .IntervalSlow )
327
- cancelFunc ()
328
+ cleanupCancel ()
328
329
<- done
329
330
cleanupLogsStr := cleanupLogs .String ()
330
331
require .Contains (t , cleanupLogsStr , "canceling workspace build" )
0 commit comments