gh-151540: Use a selector event loop in the happy-eyeballs tests#153375
Conversation
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.
|
Test changes do not need news. |
|
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 |
|
@kumaraditya303 Thank you for the update, I removed the news entry |
|
Thanks @jmrossi98 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @jmrossi98 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Thanks @jmrossi98 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
Sorry, @jmrossi98 and @kumaraditya303, I could not cleanly backport this to |
|
Sorry, @jmrossi98 and @kumaraditya303, I could not cleanly backport this to |
|
GH-154623 is a backport of this pull request to the 3.15 branch. |
test_create_connection_happy_eyeballsandtest_create_connection_happy_eyeballs_ipv4_onlyintest.test_asyncio.test_base_eventscreate their event loop withasyncio.new_event_loop(), which defaults toProactorEventLoopon 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 aMagicMocksocket (fromtest_utils.mock_nonblocking_socket()), sofileno()returns aMagicMockand the callback fails withTypeError: an integer is required. The proactor path never consults the_add_reader/_add_writermocks 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 withasyncio.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 intest_asyncio.Verified on Windows 11 against
main: reproduced theTypeErrorbefore the change; after it,test_asyncio.test_base_events(118 tests) and the fulltest_asynciosuite (2547 tests) pass with no exceptions logged.