From ea1ff48b970937fd5bbceb18340bfd3cf26779db Mon Sep 17 00:00:00 2001 From: "Timur Kh." Date: Thu, 22 Oct 2026 18:59:20 +0300 Subject: [PATCH] fix desktop tests --- desktop/tests/test_resolver.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/desktop/tests/test_resolver.py b/desktop/tests/test_resolver.py index 396cc52..e93095e 100644 --- a/desktop/tests/test_resolver.py +++ b/desktop/tests/test_resolver.py @@ -231,18 +231,23 @@ def test_junk_on_the_socket_does_not_take_the_stub_down(stub): def test_a_dead_upstream_becomes_servfail(tmp_path): - resolver = StubResolver(ports=(0,), upstream_path=str(tmp_path / "empty.conf"), timeout=0.3) - assert resolver.start() - try: - # The file does not exist and /etc/resolv.conf points at resolved, which - # is filtered out — so there is nowhere to forward to. - with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: - sock.settimeout(2) - sock.sendto(query("example.com"), ("127.0.0.1", resolver.port)) - response, _ = sock.recvfrom(4096) - assert response[3] & 0x0F == 2 # SERVFAIL, not a lie about the address - finally: - resolver.stop() + # A socket that is bound and listening but never answers. The upstream must + # be named explicitly: an empty or missing file falls back to the machine's + # /etc/resolv.conf, which in CI is Docker's resolver and *does* answer. + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as dead: + dead.bind(("127.0.0.1", 0)) + conf = tmp_path / "resolv.conf" + conf.write_text(f"nameserver 127.0.0.1:{dead.getsockname()[1]}\n") + resolver = StubResolver(ports=(0,), upstream_path=str(conf), timeout=0.3) + assert resolver.start() + try: + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: + sock.settimeout(2) + sock.sendto(query("example.com"), ("127.0.0.1", resolver.port)) + response, _ = sock.recvfrom(4096) + assert response[3] & 0x0F == 2 # SERVFAIL, not a lie about the address + finally: + resolver.stop() def test_upstreams_are_read_from_resolv_conf_and_loops_are_dropped(tmp_path):