diff --git a/CHANGES/11293.misc.rst b/CHANGES/11293.misc.rst new file mode 100644 index 00000000000..d0b87fe2317 --- /dev/null +++ b/CHANGES/11293.misc.rst @@ -0,0 +1,4 @@ +Fixed flaky ``test_aiohttp_request_ctx_manager_not_found`` by switching the +unresolvable hostname to use the reserved ``.invalid`` TLD (RFC 2606), which is +guaranteed not to resolve, instead of relying on a real domain that could be +hijacked or unexpectedly resolved by some networks -- by :user:`copilot`. diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 51dfc6d44c9..e77c1feb6ea 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -3753,9 +3753,13 @@ async def handler(request: web.Request) -> NoReturn: async def test_aiohttp_request_ctx_manager_not_found() -> None: + # Use the reserved ``.invalid`` TLD (RFC 2606) so DNS resolution is + # guaranteed to fail, instead of relying on a real domain name which + # may unexpectedly resolve on some networks (e.g. ISP NXDOMAIN + # hijacking) and make this test flaky. See #11293. with pytest.raises(aiohttp.ClientConnectionError): - async with aiohttp.request("GET", "http://wrong-dns-name.com"): - assert False + async with aiohttp.request("GET", "http://wrong-dns-name.invalid"): + assert False, "never executed" async def test_raising_client_connector_dns_error_on_dns_failure() -> None: