Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
mafredri opened this issue Jun 7, 2022 · 1 comment · Fixed by #3170
Labels
api Area: HTTP API site Area: frontend dashboard

Comments

@mafredri
Copy link
Member

mafredri commented Jun 7, 2022

Unless ptytest output is consumed, a test can hang if a command outputs more than 1024 bytes (at least on macOS).

There are two ways to work around this issue:

  1. Consume the output via pty.ExpectMatch() (ensure no more than 1024 bytes are left unread)
  2. Use cmd.SetOut(io.Discard) instead

Since 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 to ExpectMatch.

A reproduction of this bug exists as a test in #1629 (and will be merged in and skipped on macOS and Windows).

@kylecarbs kylecarbs changed the title bug: Tests using Cobra with ptytest can hang on macOS (and Windows) unless the output is consumed Tests using Cobra with ptytest can hang on macOS (and Windows) unless the output is consumed Jun 7, 2022
@kylecarbs kylecarbs added the bug label Jun 7, 2022
@kylecarbs
Copy link
Member

@mafredri I updated the title to use the bug label instead of the prefix!

@misskniss misskniss added api Area: HTTP API site Area: frontend dashboard labels Jun 14, 2022
mafredri added a commit that referenced this issue Jul 20, 2022
mafredri added a commit that referenced this issue Jul 20, 2022
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
Labels
api Area: HTTP API site Area: frontend dashboard
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants