Skip to content

Commit f418ece

Browse files
authored
test(cli): prevent flake due to outdated build in TestSSH (coder#12760)
Fixes coder#12752
1 parent 51491fc commit f418ece

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

cli/ssh_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,26 @@ func TestSSH(t *testing.T) {
117117
clitest.SetupConfig(t, client, root)
118118
pty := ptytest.New(t).Attach(inv)
119119

120-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
120+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
121121
defer cancel()
122122

123123
cmdDone := tGo(t, func() {
124124
err := inv.WithContext(ctx).Run()
125125
assert.NoError(t, err)
126126
})
127127

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+
128140
// When the agent connects, the workspace was started, and we should
129141
// have access to the shell.
130142
_ = agenttest.New(t, client.URL, authToken)
@@ -365,7 +377,7 @@ func TestSSH(t *testing.T) {
365377
workspaceBuild := coderdtest.CreateWorkspaceBuild(t, client, workspace, database.WorkspaceTransitionStop)
366378
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspaceBuild.ID)
367379

368-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
380+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
369381
defer cancel()
370382

371383
clientStdinR, clientStdinW := io.Pipe()
@@ -461,6 +473,18 @@ func TestSSH(t *testing.T) {
461473
assert.NoError(t, err)
462474
})
463475

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+
464488
// When the agent connects, the workspace was started, and we should
465489
// have access to the shell.
466490
_ = agenttest.New(t, client.URL, authToken)

0 commit comments

Comments
 (0)