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

Fix random failures with parallel CLI tests #831

Merged
merged 2 commits into from
Oct 31, 2023
Merged

Conversation

tlento
Copy link
Contributor

@tlento tlento commented Oct 31, 2023

We use pytest-xdist for parallel test execution, which means multiple
worker threads fire up tests which are loosely grouped by class/module.

Unfortunately, there are no guarantees around any of this, so the CLI
tests, which are all in one module, may execute on different workers.
We had a bad fixture layout on the CLI tests which would touch a file
in the CLI directory and then unlink it after the test was done. If
every test ran on the same worker this was fine - only one test would
ever be accessing this path location at a time. But when the tests get
split across workers bad things happen with FileNotFound and things
of that nature.

This change moves us off of having multiple tests creating and
destroying the same file in the same file path location, instead
relying on a fixed file that already exists in a static location in
the repository.

The addition of capsys.disabled calls to the CLI tests was done
to work around an issue with files being opened and closed in the
CLI setup fixtures. When running under high parallelism the CLI
tests would occasionally be split up across worker instances, and
so the file system operations - which were effectively creating
and removing the same file - would cause failures due to race
conditions between the different test runner fixture executions.

Adding capsys.disabled didn't solve this problem, it merely made
it somewhat less likely to occur, and ultimately replaced the error
with a different one (file not found).

This commit removes the capsys.disabled calls in favor of a
follow-up to stop doing all of this filesystem manipulation.
We use pytest-xdist for parallel test execution, which means multiple
worker threads fire up tests which are loosely grouped by class/module.

Unfortunately, there are no guarantees around any of this, so the CLI
tests, which are all in one module, may execute on different workers.
We had a bad fixture layout on the CLI tests which would touch a file
in the CLI directory and then unlink it after the test was done. If
every test ran on the same worker this was fine - only one test would
ever be accessing this path location at a time. But when the tests get
split across workers bad things happen with FileNotFound and things
of that nature.

This change moves us off of having multiple tests creating and
destroying the same file in the same file path location, instead
relying on a fixed file that already exists in a static location in
the repository.
@cla-bot cla-bot bot added the cla:yes label Oct 31, 2023
Copy link
Contributor Author

tlento commented Oct 31, 2023

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@github-actions
Copy link

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

Copy link
Contributor

@courtneyholcomb courtneyholcomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh thanks for resolving this!! Thought I had something wrong with my local setup that was causing these errors 🫠

Copy link
Contributor

@plypaul plypaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about that issue - thanks for the fix!

@tlento tlento merged commit 29e06ea into main Oct 31, 2023
33 of 35 checks passed
@tlento tlento deleted the fix-cli-test-execution branch October 31, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants