Skip to content

fix: test: TestSSH_RemoteForward: wait for startup script #10211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: TestSSH_RemoteForward wait for startup script
  • Loading branch information
mtojek committed Oct 11, 2023
commit fcde4d458ae1e8fffdb58165c5cbde36d380cc62
31 changes: 22 additions & 9 deletions cli/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import (
"github.com/coder/coder/v2/testutil"
)

const (
startupScriptPattern = "i-am-ready"
)

func setupWorkspaceForAgent(t *testing.T, mutate func([]*proto.Agent) []*proto.Agent) (*codersdk.Client, codersdk.Workspace, string) {
t.Helper()
if mutate == nil {
Expand All @@ -68,6 +72,12 @@ func setupWorkspaceForAgent(t *testing.T, mutate func([]*proto.Agent) []*proto.A
Auth: &proto.Agent_Token{
Token: agentToken,
},
Scripts: []*proto.Script{
{
Script: fmt.Sprintf("echo '%s'", startupScriptPattern),
RunOnStart: true,
},
},
}}),
}},
},
Expand Down Expand Up @@ -393,12 +403,6 @@ func TestSSH(t *testing.T) {

client, workspace, agentToken := setupWorkspaceForAgent(t, nil)

_ = agenttest.New(t, client.URL, agentToken)
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)

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

inv, root := clitest.New(t,
"ssh",
workspace.Name,
Expand All @@ -408,14 +412,23 @@ func TestSSH(t *testing.T) {
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)
inv.Stderr = pty.Output()

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

cmdDone := tGo(t, func() {
err := inv.WithContext(ctx).Run()
assert.NoError(t, err, "ssh command failed")
})

// Wait for the prompt or any output really to indicate the command has
// started and accepting input on stdin.
_ = pty.Peek(ctx, 1)
// Agent is still starting
pty.ExpectMatch("Waiting")

_ = agenttest.New(t, client.URL, agentToken)
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)

// Startup script has just finished
pty.ExpectMatch(startupScriptPattern)

// Download the test page
pty.WriteLine("curl localhost:8222")
Expand Down