@@ -263,6 +263,7 @@ func Test_Runner(t *testing.T) {
263
263
}()
264
264
265
265
// Wait for the workspace build job to be picked up.
266
+ jobCh := make (chan codersdk.ProvisionerJob , 1 )
266
267
require .Eventually (t , func () bool {
267
268
workspaces , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {})
268
269
if err != nil {
@@ -273,64 +274,56 @@ func Test_Runner(t *testing.T) {
273
274
}
274
275
275
276
ws := workspaces .Workspaces [0 ]
276
- t .Logf ("checking build: %s | %s" , ws .LatestBuild .Transition , ws .LatestBuild .Job .Status )
277
+ t .Logf ("checking build: %s | %s | %s" , ws . ID , ws .LatestBuild .Transition , ws .LatestBuild .Job .Status )
277
278
// There should be only one build at present.
278
279
if ws .LatestBuild .Transition != codersdk .WorkspaceTransitionStart {
279
280
t .Errorf ("expected build transition %s, got %s" , codersdk .WorkspaceTransitionStart , ws .LatestBuild .Transition )
280
281
return false
281
282
}
282
- return ws .LatestBuild .Job .Status == codersdk .ProvisionerJobRunning
283
- }, testutil .WaitShort , testutil .IntervalMedium )
284
283
284
+ if ws .LatestBuild .Job .Status != codersdk .ProvisionerJobRunning {
285
+ return false
286
+ }
287
+ jobCh <- ws .LatestBuild .Job
288
+ return true
289
+ }, testutil .WaitLong , testutil .IntervalSlow )
290
+
291
+ t .Log ("canceling scaletest workspace creation" )
285
292
cancelFunc ()
286
293
<- done
287
-
288
- ctx = testutil .Context (t , testutil .WaitLong ) // Reset ctx to avoid timeouts.
294
+ t .Log ("canceled scaletest workspace creation" )
295
+ // Ensure we have a job to interrogate
296
+ runningJob := testutil .RequireRecvCtx (testutil .Context (t , testutil .WaitShort ), t , jobCh )
297
+ require .NotZero (t , runningJob .ID )
289
298
290
299
// When we run the cleanup, it should be canceled
291
300
cleanupLogs := bytes .NewBuffer (nil )
292
- cancelCtx , cancelFunc = context .WithCancel (ctx )
301
+ // Reset ctx to avoid timeouts.
302
+ cancelCtx , cancelFunc = context .WithTimeout (context .Background (), testutil .WaitLong )
293
303
done = make (chan struct {})
294
304
go func () {
295
305
// This will return an error as the "delete" operation will never complete.
296
306
_ = runner .Cleanup (cancelCtx , "1" , cleanupLogs )
297
307
close (done )
298
308
}()
299
309
300
- // Ensure the job has been marked as deleted
310
+ // Ensure the job has been marked as canceled
301
311
require .Eventually (t , func () bool {
302
- workspaces , err := client .Workspaces (ctx , codersdk. WorkspaceFilter {} )
303
- if err != nil {
312
+ pj , err := client .OrganizationProvisionerJob (ctx , runningJob . OrganizationID , runningJob . ID )
313
+ if ! assert . NoError ( t , err ) {
304
314
return false
305
315
}
306
316
307
- if len (workspaces .Workspaces ) == 0 {
308
- return false
309
- }
317
+ t .Logf ("provisioner job id:%s status:%s" , pj .ID , pj .Status )
310
318
311
- // There should be two builds
312
- builds , err := client .WorkspaceBuilds (ctx , codersdk.WorkspaceBuildsRequest {
313
- WorkspaceID : workspaces .Workspaces [0 ].ID ,
314
- })
315
- if err != nil {
319
+ if pj .Status != codersdk .ProvisionerJobFailed &&
320
+ pj .Status != codersdk .ProvisionerJobCanceling &&
321
+ pj .Status != codersdk .ProvisionerJobCanceled {
316
322
return false
317
323
}
318
- for i , build := range builds {
319
- t .Logf ("checking build #%d: %s | %s" , i , build .Transition , build .Job .Status )
320
- // One of the builds should be for creating the workspace,
321
- if build .Transition != codersdk .WorkspaceTransitionStart {
322
- continue
323
- }
324
-
325
- // And it should be either failed (Echo returns an error when job is canceled), canceling, or canceled.
326
- if build .Job .Status == codersdk .ProvisionerJobFailed ||
327
- build .Job .Status == codersdk .ProvisionerJobCanceling ||
328
- build .Job .Status == codersdk .ProvisionerJobCanceled {
329
- return true
330
- }
331
- }
332
- return false
333
- }, testutil .WaitShort , testutil .IntervalMedium )
324
+
325
+ return true
326
+ }, testutil .WaitLong , testutil .IntervalSlow )
334
327
cancelFunc ()
335
328
<- done
336
329
cleanupLogsStr := cleanupLogs .String ()
0 commit comments