gh-151540: Use a selector event loop in the happy-eyeballs tests#153375
Open
jmrossi98 wants to merge 1 commit into
Open
gh-151540: Use a selector event loop in the happy-eyeballs tests#153375jmrossi98 wants to merge 1 commit into
jmrossi98 wants to merge 1 commit into
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.