From 9bd2b826bebae119a97972c479cf94a52f4c52bf Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 26 Mar 2024 12:24:43 +0200 Subject: [PATCH 1/2] test(cli): Prevent flake due to outdated build in TestSSH --- cli/ssh_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index cc88bc52d7e5b..569f6784ce0ed 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -365,7 +365,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 +461,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) From 4c4fcad4245e23ce6b9a8274cf7660eef5742496 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 26 Mar 2024 12:31:46 +0200 Subject: [PATCH 2/2] add delay to StartStoppedWorkspace as well --- cli/ssh_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index 569f6784ce0ed..f1e52b1a0c0ef 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)