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

Re-introduce pytest-xdist in supported envs #5431

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

webknjaz
Copy link
Member

@webknjaz webknjaz commented Jan 25, 2021

What do these changes do?

This change resurrects parallel test execution in most of the test envs. On my laptop, the full test run is almost 3x faster: 36.04s vs 105.53s (0:01:45).

Refs:

Are there changes in behavior for the user?

Nope.

Related issue number

#3419 + #3450

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .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.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@webknjaz webknjaz added infra bot:chronographer:skip This PR does not need to include a change note backport-3.8 labels Jan 25, 2021
@webknjaz webknjaz force-pushed the testing/pytest-xdist branch 3 times, most recently from 7ed6246 to 392ebbb Compare January 25, 2021 12:32
@webknjaz webknjaz marked this pull request as draft January 25, 2021 14:36
@codecov
Copy link

codecov bot commented Jan 25, 2021

Codecov Report

Attention: Patch coverage is 98.82353% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.64%. Comparing base (5a9e500) to head (7333846).
Report is 910 commits behind head on master.

Files with missing lines Patch % Lines
tests/test_connector.py 98.43% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5431   +/-   ##
=======================================
  Coverage   97.64%   97.64%           
=======================================
  Files         107      107           
  Lines       33317    33392   +75     
  Branches     3916     3924    +8     
=======================================
+ Hits        32531    32605   +74     
- Misses        568      569    +1     
  Partials      218      218           
Flag Coverage Δ
CI-GHA 97.55% <98.82%> (+<0.01%) ⬆️
OS-Linux 97.21% <98.82%> (+<0.01%) ⬆️
OS-Windows 95.65% <98.82%> (+<0.01%) ⬆️
OS-macOS 96.88% <98.82%> (+<0.01%) ⬆️
Py-3.10.11 97.01% <97.64%> (+<0.01%) ⬆️
Py-3.10.14 96.96% <97.64%> (+<0.01%) ⬆️
Py-3.11.9 97.19% <97.64%> (+<0.01%) ⬆️
Py-3.12.4 97.37% <97.64%> (+0.05%) ⬆️
Py-3.8.10 95.41% <97.64%> (+<0.01%) ⬆️
Py-3.8.18 96.85% <97.64%> (+<0.01%) ⬆️
Py-3.9.13 97.00% <97.64%> (-0.01%) ⬇️
Py-3.9.19 96.95% <97.64%> (-0.01%) ⬇️
Py-pypy7.3.16 96.52% <97.64%> (+<0.01%) ⬆️
VM-macos 96.88% <98.82%> (+<0.01%) ⬆️
VM-ubuntu 97.21% <98.82%> (+<0.01%) ⬆️
VM-windows 95.65% <98.82%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

from typing import TYPE_CHECKING, List

try:
from asyncio import ThreadedChildWatcher

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'ThreadedChildWatcher' is not used.
@webknjaz webknjaz added the backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot label Jan 28, 2024
This was referenced Apr 19, 2024
@webknjaz webknjaz linked an issue Apr 19, 2024 that may be closed by this pull request
1 task
@webknjaz webknjaz force-pushed the testing/pytest-xdist branch 2 times, most recently from b6a6440 to 1989754 Compare April 29, 2024 00:05
@webknjaz
Copy link
Member Author

@Dreamsorcerer @bdraco any ideas why the http parser tests might be failing in with pytest-xdist?

tests/test_connector.py Outdated Show resolved Hide resolved
@webknjaz webknjaz closed this Jul 19, 2024
@webknjaz webknjaz reopened this Jul 19, 2024
tests/test_connector.py Outdated Show resolved Hide resolved
tests/test_connector.py Outdated Show resolved Hide resolved
tests/test_connector.py Outdated Show resolved Hide resolved
tests/_pytest_plugin.py Outdated Show resolved Hide resolved
@webknjaz webknjaz requested review from bdraco and Dreamsorcerer and removed request for asvetlov July 21, 2024 23:41
@webknjaz
Copy link
Member Author

@Dreamsorcerer @bdraco could you check the changes in tests especially carefully? Looks like I made it work, and it makes the CI complete 3x faster. Some cleanup pending. But I'm mostly worried about the changes in tests — perhaps you'd be able to point out better ways of dealing with them.

@@ -118,6 +119,7 @@ async def test_secure_https_proxy_absolute_path(

await sess.close()
await conn.close()
await asyncio.sleep(0.1)
Copy link
Member

Choose a reason for hiding this comment

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

0.1 seems a bit brittle. Does this need one iteration of the event loop or is it waiting for a specific timer?

Suggested change
await asyncio.sleep(0.1)
await asyncio.sleep(0)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure. I was experimenting w/o really debugging in many of the cases. And sometimes 0 wasn't helping… I'll need to take a look again, I suppose.

@@ -190,6 +192,8 @@ async def test_https_proxy_unsupported_tls_in_tls(
await sess.close()
await conn.close()

await asyncio.sleep(0.1)
Copy link
Member

Choose a reason for hiding this comment

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

@bdraco
Copy link
Member

bdraco commented Jul 22, 2024

@Dreamsorcerer @bdraco could you check the changes in tests especially carefully? Looks like I made it work, and it makes the CI complete 3x faster. Some cleanup pending. But I'm mostly worried about the changes in tests — perhaps you'd be able to point out better ways of dealing with them.

The test changes seem fine. However asyncio.sleep(0.x) always worries me because they tend to break over time. I try to only use asyncio.sleep(0), and if more than one iteration is needed of the event loop, than I try to patch in some synchronization with a Future or Event. In Home Assistant we have a call_soon at the end of each test to give aiohttp one more event loop iteration to shutdown https://github.com/home-assistant/core/blob/4eb096cb0a593bc35f9cd9a2b3c797d2700a4aff/tests/common.py#L369 for similar reasons

@webknjaz webknjaz requested a review from bdraco July 22, 2024 00:33
@webknjaz webknjaz marked this pull request as ready for review July 22, 2024 00:33
@@ -1906,6 +2012,8 @@ def check_with_exc(err):

assert not conn._waiters

yield from conn.close()
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this function should just be converted to an async function? Maybe the test just predates async syntax...

The codecov comment says that it's not running though, which makes sense given all we are doing is creating a generator object. So, we never actually run any of the function body...

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an interesting idea… I'll have to check. I'm tired, working on this patch on and off for years. So at this point, I'm almost ready to accept any suggestion that would get this merged. I just want to be careful not to break anything. I think the last couple of times (like 6–7 years ago) I attempted integrating xdist here, and it brought a lot of flakiness that would become evident in Travis CI. So I'm both invested and annoyed at this point :)

@Dreamsorcerer
Copy link
Member

In Home Assistant we have a call_soon at the end of each test to give aiohttp one more event loop iteration to shutdown https://github.com/home-assistant/core/blob/4eb096cb0a593bc35f9cd9a2b3c797d2700a4aff/tests/common.py#L369 for similar reasons

I was under the impression this should not be needed on master (v4) anymore, so shouldn't be a factor in these tests. Unless it is something different from: https://docs.aiohttp.org/en/stable/client_advanced.html#graceful-shutdown

@bdraco bdraco added backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot and removed backport-3.9 labels Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot bot:chronographer:skip This PR does not need to include a change note infra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use pytest-xdist?
3 participants