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
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.

3 participants