test: Improve TestSSH/ForwardGPG stability on macOS via pty.ReadRune (#5739)

Writing to stdin for `coder ssh` too early could result in the input
being discarded. To work around this we add a new `ptytest` method
called `ReadRune` that lets us read one character of output. This will
indicate the command is ready to accept input.

It could be one character of the prompt, or of the loading message
waiting for connection to be established.
This commit is contained in:
Mathias Fredriksson
2023-01-17 15:30:47 +02:00
committed by GitHub
parent db7877012c
commit 77e71f3ca4
2 changed files with 45 additions and 0 deletions
+4
View File
@@ -475,6 +475,10 @@ Expire-Date: 0
// real error from being printed.
t.Cleanup(cancel)
// Wait for the prompt or any output really to indicate the command has
// started and accepting input on stdin.
_ = pty.ReadRune(ctx)
pty.WriteLine("echo hello 'world'")
pty.ExpectMatch("hello world")