@@ -107,8 +107,7 @@ func Test_Runner(t *testing.T) {
107
107
version = coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
108
108
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
109
109
110
- closer := goEventuallyStartFakeAgent (ctx , t , client , authToken )
111
- t .Cleanup (closer )
110
+ closerCh := goEventuallyStartFakeAgent (ctx , t , client , authToken )
112
111
113
112
const (
114
113
username = "scaletest-user"
@@ -147,6 +146,10 @@ func Test_Runner(t *testing.T) {
147
146
t .Log ("Runner logs:\n \n " + logsStr )
148
147
require .NoError (t , err )
149
148
149
+ // Wait for the workspace agent to start.
150
+ closer := <- closerCh
151
+ t .Cleanup (func () { _ = closer .Close () })
152
+
150
153
// Ensure a user and workspace were created.
151
154
users , err := client .Users (ctx , codersdk.UsersRequest {})
152
155
require .NoError (t , err )
@@ -373,8 +376,7 @@ func Test_Runner(t *testing.T) {
373
376
version = coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
374
377
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
375
378
376
- closer := goEventuallyStartFakeAgent (ctx , t , client , authToken )
377
- t .Cleanup (closer )
379
+ closeCh := goEventuallyStartFakeAgent (ctx , t , client , authToken )
378
380
379
381
const (
380
382
username = "scaletest-user"
@@ -414,6 +416,10 @@ func Test_Runner(t *testing.T) {
414
416
t .Log ("Runner logs:\n \n " + logsStr )
415
417
require .NoError (t , err )
416
418
419
+ // Wait for the agent to start.
420
+ closer := <- closeCh
421
+ t .Cleanup (func () { _ = closer .Close () })
422
+
417
423
// Ensure a user and workspace were created.
418
424
users , err := client .Users (ctx , codersdk.UsersRequest {})
419
425
require .NoError (t , err )
@@ -519,7 +525,7 @@ func Test_Runner(t *testing.T) {
519
525
// listing workspaces until we find it, then wait for the build to
520
526
// finish, then start the agents. It is the caller's responsibility to
521
527
// call the returned function to stop the agents.
522
- func goEventuallyStartFakeAgent (ctx context.Context , t * testing.T , client * codersdk.Client , agentToken string ) func () {
528
+ func goEventuallyStartFakeAgent (ctx context.Context , t * testing.T , client * codersdk.Client , agentToken string ) chan io. Closer {
523
529
t .Helper ()
524
530
ch := make (chan io.Closer , 1 ) // Don't block.
525
531
go func () {
@@ -537,7 +543,7 @@ func goEventuallyStartFakeAgent(ctx context.Context, t *testing.T, client *coder
537
543
break
538
544
}
539
545
540
- time .Sleep (100 * time . Millisecond )
546
+ time .Sleep (testutil . IntervalMedium )
541
547
}
542
548
543
549
coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , workspace .LatestBuild .ID )
@@ -549,13 +555,12 @@ func goEventuallyStartFakeAgent(ctx context.Context, t *testing.T, client *coder
549
555
Logger : slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).
550
556
Named ("agent" ).Leveled (slog .LevelWarn ),
551
557
})
552
- coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
558
+ resources := coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
559
+ assert .GreaterOrEqual (t , len (resources ), 1 , "workspace %s has no resources" , workspace .ID .String ())
560
+ assert .NotEmpty (t , resources [0 ].Agents , "workspace %s has no agents" , workspace .ID .String ())
561
+ agentID := resources [0 ].Agents [0 ].ID
562
+ t .Logf ("agent %s is running for workspace %s" , agentID .String (), workspace .ID .String ())
553
563
ch <- agentCloser
554
564
}()
555
- closeFunc := func () {
556
- if closer , ok := <- ch ; ok {
557
- _ = closer .Close ()
558
- }
559
- }
560
- return closeFunc
565
+ return ch
561
566
}
0 commit comments