8000 fix: Make TestAgent and TestWorkspaceAgentPTY less flaky by dwahler · Pull Request #1562 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: Make TestAgent and TestWorkspaceAgentPTY less flaky #1562

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 3 commits into from
May 18, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Sleep before sending command
  • Loading branch information
dwahler committed May 18, 2022
commit bf9c363cd02dddaacdbd8787b393f38351183736
4 changes: 4 additions & 0 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func TestAgent(t *testing.T) {
require.NoError(t, err)
bufRead := bufio.NewReader(netConn)

// Brief pause to reduce the likelihood that we send keystrokes while
// the shell is simultaneously sending a prompt.
time.Sleep(100 * time.Millisecond)
Comment on lines +210 to +212
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should properly be buffered on the server-side, were you seeing it differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a problem with the server, just an inherent race. The actual issue I was seeing was that the test was sending the command before it received the prompt, which means the command text actually got echoed twice. This is because after bash prints the prompt, it helpfully re-echoes anything that was pending in the input buffer, in order to make line editing work properly.

For instance, if you type sleep 10<ENTER>echo foo<ENTER> quickly, you get output on your terminal that looks like:

$ sleep 10
echo foo
$ echo foo
foo

It would certainly be cleaner to wait for the prompt and then send the input, but I'm not sure that we can easily/portably do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see. Makes sense!


data, err := json.Marshal(agent.ReconnectingPTYRequest{
Data: "echo test\r\n",
})
Expand Down
0