-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Ascola/add parallel testing #5852
Ascola/add parallel testing #5852
Conversation
Add a testing dependency on `pytest-xdist` for running pytests in parallel. I'm not sure if I ran the `pip-compile` command correctly here because there seem to be more changes than I would expect? In particular I ran it with Python3.7 but maybe I should have run it with Python3.8?
Add an `xtest` Makefile target for running pytests in parallel. The `n -auto` flag tells `pytest-xdist` to use as many processes as the CPU cores that the machine has.
Update the contributing documentation to include the parallel testing command.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5852 +/- ##
==========================================
+ Coverage 96.75% 96.78% +0.03%
==========================================
Files 44 44
Lines 9851 9851
Branches 1591 1591
==========================================
+ Hits 9531 9534 +3
+ Misses 182 179 -3
Partials 138 138
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
docs/contributing.rst
Outdated
@@ -141,6 +141,12 @@ Please take a look on the produced output. | |||
|
|||
Any extra texts (print statements and so on) should be removed. | |||
|
|||
Tests can also be run in parallel with: | |||
|
|||
.. code-block:: shell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be something like console
. shell
is for shell-scripts but console
recognizes prompts (like $
or >
) with commands and their outputs. See the pygments
lexers lists for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also mention that parallel run is experimental in the documentation unless it become stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Though per my observations, locally it's mostly stable (unless you have a million chrome tabs plus something heavy running in the background like I do) but in CI, weird random failures will be happening more often.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the lexer spec though it now is inconsistent will all the other lexers in the file (not sure if we want to fix this here or in another PR?) Also added a note about it being experimental.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I attempted implementing this in the past, back when Travis CI was a thing. And there were flaky problems with certain envs so we reverted this in the end. Earlier this year, I tried again. I managed to address many problems but not all. See #5431 for that last try.
TL;DR The I/O loop must always run in the main thread in order for the signal handling to work. With pytest-xdist it's not always the case because sometimes the underlying lib execnet
occupies that main thread with something else in an inconsistent manner. It now happens very rarely and is hard to reproduce — on my laptop, I had to make like 12-15 terminal tabs and invoke parallelized pytest in all of them (almost) simultaneously. Please follow the pointers in #5431 for more details.
In my last draft (#5431), I've tried auto-enabling pytest-xdist automatically under Python3.8+ with a new watcher that is capable of handling signals in threads. It is now on hold as I don't have time to continue exploring the problem at the moment but feel free to cherry-pick my commits into your branch (and maybe rebase on top) and try to check how well that'd work by overloading your system with many parallel processes and threads (that underlying race condition is most likely happen in such an env). Also, make sure to transfer any explanations/pointers from my PR so that all the info is consolidated here.
Lastly, I wanted to mention that I like the approach of having a separate make target. Ideally, though, the parallelized test run should be made default at some point and used in CI where any speed-ups are very welcome as well.
FTR just merged PR #5862 should've made xdist runs more stable on Python 3.8+ thanks to @sweatybridge. So I encourage everybody involved to test how it performs under heavy load + rebase this PR. |
@webknjaz Thanks for the background information. I was unaware of the previous effort. After the merge I haven't seen any signs of flakiness? I also agree that it would be nice for this to be the default behavior (eventually). |
@webknjaz I've drafted a proposal to add a .PHONY: xtest
xtest: .develop
@pytest -n auto -q --aiohttp-skip-watcher
@pytest -q tests/test_loop.py::test_subprocess_co Linking the PR here for comments. |
I tested I will change to |
@sweatybridge does this PR require #5877 to be merged first? |
FTR it looks like this PR is going to end up being covered by #5431. There's been updates to |
We were able to finally integrate |
What do these changes do?
pytest-xdist
pip-compile
dev.txt
file.)make xtest
which usespytest-xdist
make xtest
commandAre there changes in behavior for the user?
When developing
aiohttp
,make xtest
can now be used to run tests in parallel. This should be significantly faster than running the tests sequentially.Related issue number
Resolves #5849
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.