From f418ece9ae230c3685658ac6b41fd699692754f6 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 26 Mar 2024 12:46:58 +0200 Subject: [PATCH] test(cli): prevent flake due to outdated build in TestSSH (#12760) Fixes #12752 --- cli/ssh_test.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index cc88bc52d7..f1e52b1a0c 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -117,7 +117,7 @@ func TestSSH(t *testing.T) { clitest.SetupConfig(t, client, root) pty := ptytest.New(t).Attach(inv) - ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong) defer cancel() cmdDone := tGo(t, func() { @@ -125,6 +125,18 @@ func TestSSH(t *testing.T) { assert.NoError(t, err) }) + // Delay until workspace is starting, otherwise the agent may be + // booted due to outdated build. + var err error + for { + workspace, err = client.Workspace(ctx, workspace.ID) + require.NoError(t, err) + if workspace.LatestBuild.Transition == codersdk.WorkspaceTransitionStart { + break + } + time.Sleep(testutil.IntervalFast) + } + // When the agent connects, the workspace was started, and we should // have access to the shell. _ = agenttest.New(t, client.URL, authToken) @@ -365,7 +377,7 @@ func TestSSH(t *testing.T) { workspaceBuild := coderdtest.CreateWorkspaceBuild(t, client, workspace, database.WorkspaceTransitionStop) coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspaceBuild.ID) - ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong) defer cancel() clientStdinR, clientStdinW := io.Pipe() @@ -461,6 +473,18 @@ func TestSSH(t *testing.T) { assert.NoError(t, err) }) + // Delay until workspace is starting, otherwise the agent may be + // booted due to outdated build. + var err error + for { + workspace, err = client.Workspace(ctx, workspace.ID) + require.NoError(t, err) + if workspace.LatestBuild.Transition == codersdk.WorkspaceTransitionStart { + break + } + time.Sleep(testutil.IntervalFast) + } + // When the agent connects, the workspace was started, and we should // have access to the shell. _ = agenttest.New(t, client.URL, authToken)