From b78ee424499496f7a2acec12f64f065db21521bc Mon Sep 17 00:00:00 2001 From: bugfix-mission Date: Thu, 23 Apr 2026 01:05:48 +0800 Subject: [PATCH] fix(tests): use .invalid TLD for unresolvable DNS test test_aiohttp_request_ctx_manager_not_found was flaky on networks where 'wrong-dns-name.com' could occasionally resolve (e.g. ISP NXDOMAIN hijacking or transient parking entries), causing the request to proceed and trip the inner assertion. Switch to the reserved .invalid TLD (RFC 2606), which is guaranteed never to resolve. --- CHANGES/11293.misc.rst | 4 ++++ tests/test_client_functional.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 CHANGES/11293.misc.rst 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: