@@ -117,14 +117,26 @@ func TestSSH(t *testing.T) {
117
117
clitest .SetupConfig (t , client , root )
118
118
pty := ptytest .New (t ).Attach (inv )
119
119
120
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
120
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitSuperLong )
121
121
defer cancel ()
122
122
123
123
cmdDone := tGo (t , func () {
124
124
err := inv .WithContext (ctx ).Run ()
125
125
assert .NoError (t , err )
126
126
})
127
127
128
+ // Delay until workspace is starting, otherwise the agent may be
129
+ // booted due to outdated build.
130
+ var err error
131
+ for {
132
+ workspace , err = client .Workspace (ctx , workspace .ID )
133
+ require .NoError (t , err )
134
+ if workspace .LatestBuild .Transition == codersdk .WorkspaceTransitionStart {
135
+ break
136
+ }
137
+ time .Sleep (testutil .IntervalFast )
138
+ }
139
+
128
140
// When the agent connects, the workspace was started, and we should
129
141
// have access to the shell.
130
142
_ = agenttest .New (t , client .URL , authToken )
@@ -365,7 +377,7 @@ func TestSSH(t *testing.T) {
365
377
workspaceBuild := coderdtest .CreateWorkspaceBuild (t , client , workspace , database .WorkspaceTransitionStop )
366
378
coderdtest .AwaitWorkspaceBuildJobCompleted (t , client , workspaceBuild .ID )
367
379
368
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
380
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitSuperLong )
369
381
defer cancel ()
370
382
371
383
clientStdinR , clientStdinW := io .Pipe ()
@@ -461,6 +473,18 @@ func TestSSH(t *testing.T) {
461
473
assert .NoError (t , err )
462
474
})
463
475
476
+ // Delay until workspace is starting, otherwise the agent may be
477
+ // booted due to outdated build.
478
+ var err error
479
+ for {
480
+ workspace , err = client .Workspace (ctx , workspace .ID )
481
+ require .NoError (t , err )
482
+ if workspace .LatestBuild .Transition == codersdk .WorkspaceTransitionStart {
483
+ break
484
+ }
485
+ time .Sleep (testutil .IntervalFast )
486
+ }
487
+
464
488
// When the agent connects, the workspace was started, and we should
465
489
// have access to the shell.
466
490
_ = agenttest .New (t , client .URL , authToken )
0 commit comments