Skip to content
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

bats/background-process: Close file descriptor 3 #227

Merged
merged 2 commits into from
Jun 9, 2018
Merged

Conversation

mbland
Copy link
Owner

@mbland mbland commented Dec 5, 2017

Closes #226. From the comment within run_in_background:

Bats duplicates standard output as file descriptor 3 so that output from its framework functions isn't captured along with any output from the code under test. If the code under test contains a sleep or other blocking operation, this file descriptor will be held open until the process becomes unblocked, preventing Bats from exiting. Hence, we explicitly close file descriptor 3.

Any other code running under Bats that opens a background process should close this file descriptor as well. See: sstephenson/bats#80

Much thanks to @marascio for discovering and researching the problem, and proposing the actual fix.

Closes #226. From the comment within `run_in_background`:

Bats duplicates standard output as file descriptor 3 so that output from
its framework functions isn't captured along with any output from the
code under test. If the code under test contains a `sleep` or other
blocking operation, this file descriptor will be held open until the
process becomes unblocked, preventing Bats from exiting. Hence, we
explicitly close file descriptor 3.

Any other code running under Bats that opens a background process should
close this file descriptor as well. See:
sstephenson/bats#80

Much thanks to @marascio for discovering and researching the problem,
and proposing the actual fix.
@coveralls
Copy link

coveralls commented Dec 5, 2017

Coverage Status

Coverage remained the same at 95.025% when pulling dbf7048 on close-bats-fd-3 into c82223e on master.

@mbland
Copy link
Owner Author

mbland commented Dec 5, 2017

Very strange...Coveralls is starting to count the kcov files towards coverage. Will look into this in a little bit: https://coveralls.io/builds/14508796

@mbland
Copy link
Owner Author

mbland commented Dec 6, 2017

The coverage dropped because SimonKagstrom/kcov@0dd22bd added the ability for kcov to automatically discover all scripts residing in the same directory of the script under test. In this case, it unfortunately discovered all the scripts in ./git and tests/kcov, as well as various *.md and *.yml files that happened to have "bash" in the first line regardless of the presence of a #!.

I'll file a separate PR to resolve this issue before merging this one. I may file a PR against https://github.com/SimonKagstrom/kcov as well, to ensure only files starting with #! are discovered.

mbland added a commit that referenced this pull request Jun 9, 2018
I noticed during the build for #227 that test coverage dropped
precipitously for no apparent reason:

  https://coveralls.io/builds/14508796

The coverage dropped because SimonKagstrom/kcov@0dd22bd added the
ability for kcov to automatically discover all scripts residing in the
same directory of the script under test. In this case, it unfortunately
discovered all the scripts in ./git and tests/kcov, as well as various
*.md and *.yml files that happened to have "bash" in the first line
regardless of the presence of a #!.

The interim fix for this was to add the --bash-dont-parse-binary-dir and
to update the tests accordingly.

Also, since a bit of time elapsed since I returned to the problem, I
realized the latest tip of kcov's master branch exhibited the hanging bug I
helped squash in SimonKagstrom/kcov#211. The bug was reintroduced in
SimonKagstrom/kcov@ad17136, which tried to fix a bug reported in
SimonKagstrom/kcov#248 whereby kcov would hang on output that didn't
contain newlines.

SimonKagstrom/kcov#249 attempted to resolve the bug, but didn't quite
work and was abandoned. I may take a stab at fixing it one day, but in
the meanwhile, kcov v35 with --bash-dont-parse-binary-dir works to get
this project's test coverage back in shape.
@mbland
Copy link
Owner Author

mbland commented Jun 9, 2018

Resolved the coverage issue for now by requiring kcov v35; see #244 for details.

@mbland mbland merged commit c583616 into master Jun 9, 2018
@mbland mbland deleted the close-bats-fd-3 branch June 9, 2018 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test hangs when trying basic usage of background-process when output does not match
3 participants