Skip to content

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

Open
jmrossi98 wants to merge 1 commit into
python:mainfrom
jmrossi98:fix-issue-151540
Open

gh-151540: Use a selector event loop in the happy-eyeballs tests#153375
jmrossi98 wants to merge 1 commit into
python:mainfrom
jmrossi98:fix-issue-151540

Conversation

@jmrossi98

Copy link
Copy Markdown

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.

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

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants