Skip to content

Commit 92ef0ba

Browse files
authored
fix: remove pty match for TestSSH/RemoteForward (#10789)
Fixes #10578
1 parent df4f34a commit 92ef0ba

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

cli/ssh_test.go

+22-16
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@ func TestSSH(t *testing.T) {
636636
defer httpServer.Close()
637637

638638
client, workspace, agentToken := setupWorkspaceForAgent(t, nil)
639+
_ = agenttest.New(t, client.URL, agentToken)
640+
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
639641

640642
inv, root := clitest.New(t,
641643
"ssh",
@@ -644,32 +646,36 @@ func TestSSH(t *testing.T) {
644646
"8222:"+httpServer.Listener.Addr().String(),
645647
)
646648
clitest.SetupConfig(t, client, root)
647-
pty := ptytest.New(t).Attach(inv)
648-
inv.Stderr = pty.Output()
649649

650650
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
651651
defer cancel()
652652

653653
cmdDone := tGo(t, func() {
654654
err := inv.WithContext(ctx).Run()
655-
assert.NoError(t, err, "ssh command failed")
655+
// fails because we cancel context to close
656+
assert.Error(t, err, "ssh command should fail")
656657
})
657658

658-
// Agent is still starting
659-
pty.ExpectMatch("Waiting")
660-
661-
_ = agenttest.New(t, client.URL, agentToken)
662-
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
663-
664-
// Startup script has just finished
665-
pty.ExpectMatch(startupScriptPattern)
666-
667-
// Download the test page
668-
pty.WriteLine("curl localhost:8222")
669-
pty.ExpectMatch("hello world")
659+
require.Eventually(t, func() bool {
660+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost:8222/", nil)
661+
if !assert.NoError(t, err) {
662+
// true exits the loop.
663+
return true
664+
}
665+
resp, err := http.DefaultClient.Do(req)
666+
if err != nil {
667+
t.Logf("HTTP GET http://localhost:8222/ %s", err)
668+
return false
669+
}
670+
defer resp.Body.Close()
671+
body, err := io.ReadAll(resp.Body)
672+
assert.NoError(t, err)
673+
assert.EqualValues(t, "hello world", body)
674+
return true
675+
}, testutil.WaitLong, testutil.IntervalFast)
670676

671677
// And we're done.
672-
pty.WriteLine("exit")
678+
cancel()
673679
<-cmdDone
674680
})
675681

0 commit comments

Comments
 (0)