Skip to content

detect tests that spawn subprocesses which leak handles #359

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

Merged
merged 12 commits into from
Jul 18, 2022

Conversation

sunshowers
Copy link
Member

@sunshowers sunshowers commented Jul 15, 2022

Switch to tokio for the main runner loop so we get the ability to select across pipe reads and timeouts.

Use this to detect and handle tests which spawn subprocesses that leak handles. We treat them as passing tests for now, though might make leak failures configurable in the future.

Note that we can only detect subprocesses which inherit standard input/output/error. We can't detect subprocesses spawned with piped stdio that outlive the process. That's a far more challenging problem (see duct's gotchas.md for more). However this solves the immediate problem of nextest hanging because of unclosed pipes, and is probably the most common set of issues.

TODO:

Closes #15.

@sunshowers sunshowers marked this pull request as draft July 15, 2022 21:39
@sunshowers sunshowers force-pushed the leak-detection branch 12 times, most recently from 41c01bc to fb0a6e0 Compare July 18, 2022 03:56
This will allow us to do things like select over file reads and a
timeout. It also solves some other problems such as test flakiness on
Windows (in the following commits).
* Convert relative paths to using the main separator.
* Don't add paths if they don't exist on disk.

I'd previously hypothesized that these fixes would help for Windows test
flakiness, but they don't appear to do anything. What does appear to
help is switching everything to `tokio::process::Command`, which I do in
the future.
This appears to solve several problems at once:

1. Removes the redundant `make_test_command`/`make_test_expression`
   operations.
2. Adds automatic parallelism to the list step.
3. Appears to completely solve flakiness issues on Windows GitHub
   Actions runners (nextest-rs#362).

Use the number of test threads to determine the degree of parallelism.
The flakiness issues on Windows appear to be completely resolved by the
previous commit.
This test will be marked as leaky in the future.
Detect and expose leaky tests.
This prevents issues where the test process hangs because a subprocess
inherited the stdin/out/err handles.
Some tests might accidentally read from standard input. Always close it.
Keep the same setting but make it configurable, both as a default
setting and via overrides.
@sunshowers sunshowers changed the title [WIP] detect tests that leak subprocesses detect tests that leak subprocesses Jul 18, 2022
@sunshowers sunshowers changed the title detect tests that leak subprocesses detect tests that spawn subprocesses which leak handles Jul 18, 2022
@sunshowers sunshowers marked this pull request as ready for review July 18, 2022 18:31
@sunshowers sunshowers merged commit 0eae2d0 into nextest-rs:main Jul 18, 2022
@sunshowers sunshowers deleted the leak-detection branch July 18, 2022 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail tests that leak pipes
1 participant