-
Notifications
You must be signed in to change notification settings - Fork 892
Tests using Cobra with ptytest
can hang on macOS (and Windows) unless the output is consumed
#2122
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
Comments
ptytest
can hang on macOS (and Windows) unless the output is consumedptytest
can hang on macOS (and Windows) unless the output is consumed
@mafredri I updated the title to use the |
mafredri
added a commit
that referenced
this issue
Jul 25, 2022
mafredri
added a commit
that referenced
this issue
Jul 25, 2022
mafredri
added a commit
that referenced
this issue
Aug 3, 2022
This seems to have caused flakes on Windows, the reason could be that the input is lost due to writing to stdin before the shell is ready, or simply that the command wasn't echoed (for the same reason). We no longer need to consume the output since #2122 has been fixed, so this might remove the flake in the latter case. Ideally we would wait for the prompt to be present, but since we are spawning the users shell, we have no control of what the prompt looks like. In CI we can make assumption but even then it could change in the future.
mafredri
added a commit
that referenced
this issue
Aug 3, 2022
This seems to have caused flakes on Windows, the reason could be that the input is lost due to writing to stdin before the shell is ready, or simply that the command wasn't echoed (for the same reason). We no longer need to consume the output since #2122 has been fixed, so this might remove the flake in the latter case. Ideally we would wait for the prompt to be present, but since we are spawning the users shell, we have no control of what the prompt looks like. In CI we can make assumption but even then it could change in the future.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unless
ptytest
output is consumed, a test can hang if a command outputs more than1024
bytes (at least on macOS).There are two ways to work around this issue:
pty.ExpectMatch()
(ensure no more than 1024 bytes are left unread)cmd.SetOut(io.Discard)
insteadSince using
ptytest
is a common pattern in our tests, it'd be a good idea to rewrite it so that a hang is not possible.Unless there's a bug to be fixed in underlying libraries, or changes to how ptys are configured, the most robust way to fix this would be for
ptytest
to buffer/consume all command output, irregardless of a call toExpectMatch
.A reproduction of this bug exists as a test in #1629 (and will be merged in and skipped on macOS and Windows).
The text was updated successfully, but these errors were encountered: