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

Parallelize the unit tests #16206

Merged
merged 9 commits into from
Jul 2, 2024
Merged

Conversation

woodruffw
Copy link
Member

Opening this o/b/o @DarkaMaul from @miketheman's original work.

On my local machine, this results in a ~2 speedup in testing: from roughly 2 minutes for the entire suite to 1. More speedups may be possible, e.g. in stand-up and coverage merging.

Closes #16178.

miketheman and others added 6 commits June 24, 2024 16:33
Problem with coverage measurements

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@woodruffw woodruffw requested a review from a team as a code owner July 2, 2024 14:04
@woodruffw woodruffw self-assigned this Jul 2, 2024
@woodruffw woodruffw added testing Test infrastructure and individual tests developer experience Anything that improves the experience for Warehouse devs labels Jul 2, 2024
Signed-off-by: William Woodruff <william@trailofbits.com>
Copy link
Member Author

Choose a reason for hiding this comment

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

NB: This file could probably live somewhere other than the repo root, as long as it gets copied into the right place at container time.

Copy link
Member

Choose a reason for hiding this comment

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

🤔 Since this file is being mounted in docker-compose.yml , we could place it in dev/ and mount it from there, but that would skip it from being run in CI.
I'm not opposed to leaving it where it is for now, but wanted to call that possibility out.

@woodruffw
Copy link
Member Author

woodruffw commented Jul 2, 2024

Looks like the speedup isn't as significant on CI, which is interesting.

Edit: For comparison, a random test run before this PR: https://github.com/pypi/warehouse/actions/runs/9762910094/job/26947742230

...and with this PR: https://github.com/pypi/warehouse/actions/runs/9762940705/job/26947794957?pr=16206

So 4m30s to 2m58s.

@woodruffw woodruffw requested a review from miketheman July 2, 2024 14:42
Copy link
Member

@miketheman miketheman left a comment

Choose a reason for hiding this comment

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

image

Very cool, thanks for figuring out all the pieces to this puzzle.

On my 12-core machine, drops the tests runtime from ~83 to ~41 seconds - that's about 50% speed up 🐎

Copy link
Member

Choose a reason for hiding this comment

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

🤔 Since this file is being mounted in docker-compose.yml , we could place it in dev/ and mount it from there, but that would skip it from being run in CI.
I'm not opposed to leaving it where it is for now, but wanted to call that possibility out.

@miketheman miketheman merged commit 69f8cb1 into pypi:main Jul 2, 2024
17 checks passed
@woodruffw woodruffw deleted the dm/pytest-xdist branch July 2, 2024 15:00
@di
Copy link
Member

di commented Jul 9, 2024

Is there maybe a way to locally disable this? For whatever reason, starting up the xdist workers on my machine made the test suite run take longer than it did before this change. I'm also missing the output which shows which test files failed as the test suite runs, as they're no longer displayed.

@woodruffw
Copy link
Member Author

woodruffw commented Jul 9, 2024

Is there maybe a way to locally disable this?

This should disable parallelization (by forcing everything onto one worker): make tests TESTARGS='-n 1'. On my local machine that spawns only one worker, at least.

I'll look into improving the failure render as well.

Edit: For improving the render you could pass TESTARGS='-v', although that makes the report output much more verbose than the default non-xdist output. Another option here would be to add pytest-pretty for report generation, which apparently works well with pytest-xdist. I can send a PR demonstrating that.

@di
Copy link
Member

di commented Jul 12, 2024

FWIW, looks like -n 0 fully disables pytest-xdist. Using -n 1 for me was still just as slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer experience Anything that improves the experience for Warehouse devs testing Test infrastructure and individual tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parallelize the test suite
4 participants