Skip to content

Commit 6e81f35

Browse files
committed
gh-151540: Use a selector event loop in the happy-eyeballs tests
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.
1 parent b2d8db1 commit 6e81f35

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Lib/test/test_asyncio/test_base_events.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,11 @@ async def sock_connect(sock, address):
10921092
await asyncio.sleep(1)
10931093
sock.connect(address)
10941094

1095-
loop = asyncio.new_event_loop()
1095+
# gh-151540: use a selector event loop instead of the platform
1096+
# default; the Windows proactor loop would register the mocked
1097+
# socket with a real IOCP handle instead of the mocked
1098+
# _add_reader/_add_writer below.
1099+
loop = asyncio.SelectorEventLoop()
10961100
loop._add_writer = mock.Mock()
10971101
loop._add_writer = mock.Mock()
10981102
loop._add_reader = mock.Mock()
@@ -1124,7 +1128,8 @@ async def sock_connect(sock, address):
11241128
await asyncio.sleep(1)
11251129
sock.connect(address)
11261130

1127-
loop = asyncio.new_event_loop()
1131+
# gh-151540: see test_create_connection_happy_eyeballs above.
1132+
loop = asyncio.SelectorEventLoop()
11281133
loop._add_writer = mock.Mock()
11291134
loop._add_writer = mock.Mock()
11301135
loop._add_reader = mock.Mock()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix the happy-eyeballs tests in ``test.test_asyncio.test_base_events``
2+
raising ``TypeError`` in a callback on Windows. The tests now use a
3+
selector event loop explicitly instead of the platform default, as the
4+
Windows proactor event loop registers the mocked test socket with a real
5+
I/O completion port.

0 commit comments

Comments
 (0)