10000 GH-98388: Add tests for happy eyeballs and its internal workings by twisteroidambassador · Pull Request #98389 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-98388: Add tests for happy eyeballs and its internal workings #98389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prev Previous commit
Next Next commit
Improve readability for _interleave_addrinfos tests.
  • Loading branch information
twisteroidambassador committed Oct 18, 2022
commit c0e179e8c648b2f5217c911682e92dbe3e2e905e
59 changes: 14 additions & 45 deletions Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,55 +146,24 @@ def test_ipaddr_info_no_inet_pton(self, m_socket):
socket.IPPROTO_TCP))

def test_interleave_ipaddrs(self):
addrinfos = [
(socket.AF_INET6, 0, 0, '', ('2001:db8::1', 1)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::2', 2)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::3', 3)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::4', 4)),
(socket.AF_INET, 0, 0, '', ('192.0.2.1', 5)),
(socket.AF_INET, 0, 0, '', ('192.0.2.2', 6)),
(socket.AF_INET, 0, 0, '', ('192.0.2.3', 7)),
(socket.AF_INET, 0, 0, '', ('192.0.2.4', 8)),
]
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))

self.assertEqual(
[
(socket.AF_INET6, 0, 0, '', ('2001:db8::1', 1)),
(socket.AF_INET, 0, 0, '', ('192.0.2.1', 5)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::2', 2)),
(socket.AF_INET, 0, 0, '', ('192.0.2.2', 6)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::3', 3)),
(socket.AF_INET, 0, 0, '', ('192.0.2.3', 7)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::4', 4)),
(socket.AF_INET, 0, 0, '', ('192.0.2.4', 8)),
],
base_events._interleave_addrinfos(addrinfos)
)
addrinfos = [SIX_A, SIX_B, SIX_C, SIX_D, FOUR_A, FOUR_B, FOUR_C, FOUR_D]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be a more thorough test if we mixed up the order a bit, e.g. like this?

Suggested change
addrinfos = [SIX_A, SIX_B, SIX_C, SIX_D, FOUR_A, FOUR_B, FOUR_C, FOUR_D]
addrinfos = [SIX_A, SIX_B, SIX_C, FOUR_A, FOUR_B, FOUR_C, FOUR_D, SIX_D]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @gvanrossum.

expected = [SIX_A, FOUR_A, SIX_B, FOUR_B, SIX_C, FOUR_C, SIX_D, FOUR_D]

def test_interleave_ipaddrs_first_address_family_count(self):
addrinfos = [
(socket.AF_INET6, 0, 0, '', ('2001:db8::1', 1)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::2', 2)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::3', 3)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::4', 4)),
(socket.AF_INET, 0, 0, '', ('192.0.2.1', 5)),
(socket.AF_INET, 0, 0, '', ('192.0.2.2', 6)),
(socket.AF_INET, 0, 0, '', ('192.0.2.3', 7)),
(socket.AF_INET, 0, 0, '', ('192.0.2.4', 8)),
]
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(
[
(socket.AF_INET6, 0, 0, '', ('2001:db8::1', 1)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::2', 2)),
(socket.AF_INET, 0, 0, '', ('192.0.2.1', 5)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::3', 3)),
(socket.AF_INET, 0, 0, '', ('192.0.2.2', 6)),
(socket.AF_INET6, 0, 0, '', ('2001:db8::4', 4)),
(socket.AF_INET, 0, 0, '', ('192.0.2.3', 7)),
(socket.AF_INET, 0, 0, '', ('192.0.2.4', 8)),
],
base_events._interleave_addrinfos(addrinfos, 2)
expected_fafc_2,
base_events._interleave_addrinfos(addrinfos, first_address_family_count=2),
)


Expand Down
0