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

GH-98388: Add tests for happy eyeballs and its internal workings #98389

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

twisteroidambassador
Copy link
Contributor

@twisteroidambassador twisteroidambassador commented Oct 18, 2022

One of the new tests may fail intermittently due to python#86296.
@bedevere-bot bedevere-bot added awaiting review tests Tests in the Lib/test dir labels Oct 18, 2022
@gvanrossum gvanrossum changed the title Add tests for happy eyeballs and its internal workings. GH-98388: Add tests for happy eyeballs and its internal workings Oct 18, 2022
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I've added the "skip news" label because this is a test-only PR.

Lib/test/test_asyncio/test_base_events.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@twisteroidambassador
Copy link
Contributor Author

I have made the test that exposes #86296 fail more consistently on my computer. Let's see whether these CI tests fail.

I guess the next thing to consider is: What to do with this failing test? On 3.11 and above I can replace wait_for with timeout, and I can confirm that fixes the issue, and the test passes. On older releases we don't have timeout.

@gvanrossum
Copy link
Member

On my Intel Mac I don't see these tests fail yet.

But it seems they are failing in CI, so I believe you.

I'd say let's first prepare a fix that uses timeout and see if that passes everything.

For the 3.10 backport we have to do something completely different. I wonder if the key problem here isn't the one that caused so much trouble for the Semaphore class as well -- you can await a future, and catch CancelledError, but that doesn't mean the future was cancelled, it could mean the current task was cancelled after the future already completed. Maybe there's still a path through the code that doesn't account for that, somehow?

This solution is compatible with all Python versions, and should pass all tests.
@twisteroidambassador
Copy link
Contributor Author

I got some inspiration from my past comments, and implemented a fix that's available on older Python versions as well.

The general approach is probably applicable to more situations: by waiting on the inner task with asyncio.wait, its exceptions and cancellation won't be raised automatically, and any exception caught in the outer task are definitely from the outer task itself. Once wait returns, the inner task can be inspected.

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

Once #98518 lands, please remove the implementation changes and only add tests.

@willingc
Copy link
Contributor

Hi @twisteroidambassador,

Once #98518 lands, please remove the implementation changes and only add tests.

As mentioned by @kumaraditya303: Now that #98518 has landed, would you like to modify this PR to only include the tests? Thanks.

@arhadthedev
Copy link
Member

The OP has no activity since January.

@arhadthedev
Copy link
Member

Well, working with diff using the mobile version of GitHub is extremely hard. I'll restore the deleted file in an hour after getting to a proper computer with a proper mouse.

@gvanrossum gvanrossum added the needs backport to 3.12 bug and security fixes label May 23, 2023
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

This basically LGTM, I only have very minor nits.

@arhadthedev, would you take over this PR, since @twisteroidambassador seems to have disappeared? I think it would be good to land this and backport it to 3.12. At the very least you could review my suggestions, if you agree with everything I can merge.

@willingc Did you want to add anything?

FOUR_C = (socket.AF_INET, 0, 0, '', ('192.0.2.3', 7))
FOUR_D = (socket.AF_INET, 0, 0, '', ('192.0.2.4', 8))

addrinfos = [SIX_A, SIX_B, SIX_C, SIX_D, FOUR_A, FOUR_B, FOUR_C, FOUR_D]
Copy link
Member

Choose a reason for hiding this comment

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

Would it be a more thorough test if we mixed up the order a bit, e.g. like this?

Suggested change
addrinfos = [SIX_A, SIX_B, SIX_C, SIX_D, FOUR_A, FOUR_B, FOUR_C, FOUR_D]
addrinfos = [SIX_A, SIX_B, SIX_C, FOUR_A, FOUR_B, FOUR_C, FOUR_D, SIX_D]

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM @gvanrossum.

Comment on lines +100 to +103
# There's a potential race condition here:
# https://github.com/python/cpython/issues/86296
# As with any race condition, it can be difficult to reproduce.
# This test may not fail every time.
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note to this comment that the race condition has been fixed in 3.12, e.g.

Suggested change
# There's a potential race condition here:
# https://github.com/python/cpython/issues/86296
# As with any race condition, it can be difficult to reproduce.
# This test may not fail every time.
# There's a potential race condition here (fixed in Python 3.12):
# https://github.com/python/cpython/issues/86296
# As with any race condition, it can be difficult to reproduce.
# This test may not fail every time.

@twisteroidambassador
Copy link
Contributor Author

It would be great if @arhadthedev can take over this PR, since I don't think I'll have time to work on this in the foreseeable future. Thanks in advance to everyone!

@kumaraditya303 kumaraditya303 removed their request for review July 8, 2023 08:55
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.13 bugs and security fixes label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants