Skip to content

gh-151540: Use a selector event loop in the happy-eyeballs tests - #153375

Merged
kumaraditya303 merged 2 commits into
python:mainfrom
jmrossi98:fix-issue-151540
Jul 11, 2026
Merged

gh-151540: Use a selector event loop in the happy-eyeballs tests#153375
kumaraditya303 merged 2 commits into
python:mainfrom
jmrossi98:fix-issue-151540

Conversation

@jmrossi98

Copy link
Copy Markdown
Contributor

test_create_connection_happy_eyeballs and test_create_connection_happy_eyeballs_ipv4_only in test.test_asyncio.test_base_events create their event loop with asyncio.new_event_loop(), which defaults to ProactorEventLoop on Windows. Creating the socket transport on that loop immediately registers the socket with a real I/O completion port via _overlapped.CreateIoCompletionPort(obj.fileno(), ...). The tests use a MagicMock socket (from test_utils.mock_nonblocking_socket()), so fileno() returns a MagicMock and the callback fails with TypeError: an integer is required. The proactor path never consults the _add_reader/_add_writer mocks the tests set up.

These tests exercise the platform-independent happy-eyeballs address selection in BaseEventLoop.create_connection(), not proactor behavior, so create the loop with asyncio.SelectorEventLoop() explicitly. This matches the code path the tests already exercise on non-Windows platforms, and follows the existing pattern in this file (BaseEventLoopWithSelectorTests) and elsewhere in test_asyncio.

Verified on Windows 11 against main: reproduced the TypeError before the change; after it, test_asyncio.test_base_events (118 tests) and the full test_asyncio suite (2547 tests) pass with no exceptions logged.

test_create_connection_happy_eyeballs and
test_create_connection_happy_eyeballs_ipv4_only used
asyncio.new_event_loop(), which defaults to ProactorEventLoop on
Windows. Creating a socket transport on that loop registers the
mocked socket with a real I/O completion port, bypassing the
mocked _add_reader/_add_writer and failing in a callback with
"TypeError: an integer is required" because MagicMock.fileno()
does not return an int.

Use asyncio.SelectorEventLoop() explicitly instead, matching the
code path these tests already exercise on non-Windows platforms.
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Jul 9, 2026
@python-cla-bot

python-cla-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@kumaraditya303

Copy link
Copy Markdown
Contributor

Test changes do not need news.

@bedevere-app

bedevere-app Bot commented Jul 10, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@jmrossi98

Copy link
Copy Markdown
Contributor Author

@kumaraditya303 Thank you for the update, I removed the news entry

@kumaraditya303
kumaraditya303 merged commit a1ef41a into python:main Jul 11, 2026
54 checks passed
@kumaraditya303 kumaraditya303 added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 24, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @jmrossi98 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @jmrossi98 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @jmrossi98 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app

Copy link
Copy Markdown

Sorry, @jmrossi98 and @kumaraditya303, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker a1ef41ab4198db28f63fda646200b14badb96513 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @jmrossi98 and @kumaraditya303, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker a1ef41ab4198db28f63fda646200b14badb96513 3.13

@bedevere-app

bedevere-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

GH-154623 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 24, 2026
kumaraditya303 pushed a commit that referenced this pull request Jul 25, 2026
…ts (GH-153375) (#154623)

gh-151540: Use a selector event loop in the happy-eyeballs tests (GH-153375)
(cherry picked from commit a1ef41a)

Co-authored-by: Jakob Rossi <jmrossi98@gmail.com>
@hugovk

hugovk commented Jul 29, 2026

Copy link
Copy Markdown
Member

@jmrossi98 Would you like to have a go at the backports?

@jmrossi98

Copy link
Copy Markdown
Contributor Author

@hugovk Took a look and seems like test_create_connection_happy_eyeballs/_ipv4_only were added by gh-98388 (#136368) after 3.14 branched off, so they don't exist on 3.14 or 3.13. I think the bot's conflicts are just missing code, not real conflicts. Is it worth dropping the backport labels?

@hugovk hugovk removed needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 30, 2026
@hugovk

hugovk commented Jul 30, 2026

Copy link
Copy Markdown
Member

That sounds reasonable, removed. Thanks for checking :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants