chore(cli): fix test flake caused by agent connect race (#16725)

Fixes test flake seen here:
https://github.com/coder/coder/actions/runs/13552012547/job/37877778883

```
    exp_rpty_test.go:96: 
        	Error Trace:	/home/runner/work/coder/coder/cli/exp_rpty_test.go:96
        	            				/home/runner/work/coder/coder/cli/ssh_test.go:1963
        	            				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.9.linux-amd64/src/runtime/asm_amd64.s:1695
        	Error:      	Received unexpected error:
        	            	running command "coder exp rpty": GET http://localhost:37991/api/v2/workspaceagents/3785b98f-0589-47d2-a3c8-33a55a6c5b29/containers: unexpected status code 400: Agent state is "connecting", it must be in the "connected" state.
        	Test:       	TestExpRpty/Container
```
This commit is contained in:
Cian Johnston
2025-02-26 21:10:39 +00:00
committed by GitHub
parent 81ef9e9e80
commit 2aa749a7f0
+5 -5
View File
@@ -87,6 +87,11 @@ func TestExpRpty(t *testing.T) {
require.NoError(t, err, "Could not stop container")
})
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
o.ExperimentalContainersEnabled = true
})
_ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
inv, root := clitest.New(t, "exp", "rpty", workspace.Name, "-c", ct.Container.ID)
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)
@@ -96,11 +101,6 @@ func TestExpRpty(t *testing.T) {
assert.NoError(t, err)
})
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
o.ExperimentalContainersEnabled = true
})
_ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
pty.ExpectMatch(fmt.Sprintf("Connected to %s", workspace.Name))
pty.ExpectMatch("Reconnect ID: ")
pty.ExpectMatch(" #")