mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-98388: add tests for happy eyeballs (#136368)
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
This commit is contained in:
parent
fe187fae8d
commit
0240ef4705
1 changed files with 88 additions and 0 deletions
|
@ -150,6 +150,29 @@ class BaseEventTests(test_utils.TestCase):
|
|||
socket.SOCK_STREAM,
|
||||
socket.IPPROTO_TCP))
|
||||
|
||||
def test_interleave_addrinfos(self):
|
||||
self.maxDiff = None
|
||||
SIX_A = (socket.AF_INET6, 0, 0, '', ('2001:db8::1', 1))
|
||||
SIX_B = (socket.AF_INET6, 0, 0, '', ('2001:db8::2', 2))
|
||||
SIX_C = (socket.AF_INET6, 0, 0, '', ('2001:db8::3', 3))
|
||||
SIX_D = (socket.AF_INET6, 0, 0, '', ('2001:db8::4', 4))
|
||||
FOUR_A = (socket.AF_INET, 0, 0, '', ('192.0.2.1', 5))
|
||||
FOUR_B = (socket.AF_INET, 0, 0, '', ('192.0.2.2', 6))
|
||||
FOUR_C = (socket.AF_INET, 0, 0, '', ('192.0.2.3', 7))
|
||||
FOUR_D = (socket.AF_INET, 0, 0, '', ('192.0.2.4', 8))
|
||||
|
||||
addrinfos = [SIX_A, SIX_B, SIX_C, FOUR_A, FOUR_B, FOUR_C, FOUR_D, SIX_D]
|
||||
expected = [SIX_A, FOUR_A, SIX_B, FOUR_B, SIX_C, FOUR_C, SIX_D, FOUR_D]
|
||||
|
||||
self.assertEqual(expected, base_events._interleave_addrinfos(addrinfos))
|
||||
|
||||
expected_fafc_2 = [SIX_A, SIX_B, FOUR_A, SIX_C, FOUR_B, SIX_D, FOUR_C, FOUR_D]
|
||||
self.assertEqual(
|
||||
expected_fafc_2,
|
||||
base_events._interleave_addrinfos(addrinfos, first_address_family_count=2),
|
||||
)
|
||||
|
||||
|
||||
|
||||
class BaseEventLoopTests(test_utils.TestCase):
|
||||
|
||||
|
@ -1053,6 +1076,71 @@ class BaseEventLoopTests(test_utils.TestCase):
|
|||
test_utils.run_briefly(self.loop)
|
||||
self.assertTrue(status['finalized'])
|
||||
|
||||
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'no IPv6 support')
|
||||
@patch_socket
|
||||
def test_create_connection_happy_eyeballs(self, m_socket):
|
||||
|
||||
class MyProto(asyncio.Protocol):
|
||||
pass
|
||||
|
||||
async def getaddrinfo(*args, **kw):
|
||||
return [(socket.AF_INET6, 0, 0, '', ('2001:db8::1', 1)),
|
||||
(socket.AF_INET, 0, 0, '', ('192.0.2.1', 5))]
|
||||
|
||||
async def sock_connect(sock, address):
|
||||
if address[0] == '2001:db8::1':
|
||||
await asyncio.sleep(1)
|
||||
sock.connect(address)
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
loop._add_writer = mock.Mock()
|
||||
loop._add_writer = mock.Mock()
|
||||
loop._add_reader = mock.Mock()
|
||||
loop.getaddrinfo = getaddrinfo
|
||||
loop.sock_connect = sock_connect
|
||||
|
||||
coro = loop.create_connection(MyProto, 'example.com', 80, happy_eyeballs_delay=0.3)
|
||||
transport, protocol = loop.run_until_complete(coro)
|
||||
try:
|
||||
sock = transport._sock
|
||||
sock.connect.assert_called_with(('192.0.2.1', 5))
|
||||
finally:
|
||||
transport.close()
|
||||
test_utils.run_briefly(loop) # allow transport to close
|
||||
loop.close()
|
||||
|
||||
@patch_socket
|
||||
def test_create_connection_happy_eyeballs_ipv4_only(self, m_socket):
|
||||
|
||||
class MyProto(asyncio.Protocol):
|
||||
pass
|
||||
|
||||
async def getaddrinfo(*args, **kw):
|
||||
return [(socket.AF_INET, 0, 0, '', ('192.0.2.1', 5)),
|
||||
(socket.AF_INET, 0, 0, '', ('192.0.2.2', 6))]
|
||||
|
||||
async def sock_connect(sock, address):
|
||||
if address[0] == '192.0.2.1':
|
||||
await asyncio.sleep(1)
|
||||
sock.connect(address)
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
loop._add_writer = mock.Mock()
|
||||
loop._add_writer = mock.Mock()
|
||||
loop._add_reader = mock.Mock()
|
||||
loop.getaddrinfo = getaddrinfo
|
||||
loop.sock_connect = sock_connect
|
||||
|
||||
coro = loop.create_connection(MyProto, 'example.com', 80, happy_eyeballs_delay=0.3)
|
||||
transport, protocol = loop.run_until_complete(coro)
|
||||
try:
|
||||
sock = transport._sock
|
||||
sock.connect.assert_called_with(('192.0.2.2', 6))
|
||||
finally:
|
||||
transport.close()
|
||||
test_utils.run_briefly(loop) # allow transport to close
|
||||
loop.close()
|
||||
|
||||
|
||||
class MyProto(asyncio.Protocol):
|
||||
done = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue