fix: Make TestAgent and TestWorkspaceAgentPTY less flaky #1562
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TestAgent/ReconnectingPTY was making some fragile assumptions about the data returned from a
net.Conn
. This PR makes it a bit more robust.The previous version was sending
echo test
via a PTY, and then expecting to see the stringtest
in the output twice: once from the echoed command line, and once from the command output itself. But it was expecting them to be returned by two different calls toRead()
, and there's no guarantee of that.The new version uses buffered I/O to read one line at a time, and expects to see at least one line that contains
echo test
, followed by at least one line that containstest
but notecho
. It also sleeps for 100ms to reduce the likelihood that the shell prompt test will be interleaved with the local echo of the command.There's still some room for improvement here, because ideally the test would be controlling both ends of the PTY, instead of just assuming the user's shell behaves predictably.
Fixes #1348, fixes #1368