From: Nicki Křížek Date: Thu, 11 Jun 2026 09:36:30 +0000 (+0000) Subject: fixup! Port TCP request statistics checks to Python X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b75d0b6fcd2c0b71201c5a93f7abedbab5ff95ea;p=thirdparty%2Fbind9.git fixup! Port TCP request statistics checks to Python Assisted-by: Claude:claude-fable-5 --- diff --git a/bin/tests/system/tcp/tests_tcp.py b/bin/tests/system/tcp/tests_tcp.py index 0e6b96e6a73..b788a96d62c 100644 --- a/bin/tests/system/tcp/tests_tcp.py +++ b/bin/tests/system/tcp/tests_tcp.py @@ -24,6 +24,7 @@ import time import dns.message import dns.name import dns.query +import dns.rcode import dns.rrset import pytest @@ -369,6 +370,24 @@ def test_tcp_big(named_port: int) -> None: tcp_round_trip(sock, msg) +def wait_for_stable_tcp_requests(ns: NamedInstance, timeout: int = 10) -> int: + """Read the TCP request counter until it stops changing. + + The counter is incremented on request receipt, so a client response + implies its upstream queries are already counted; this only needs to + absorb unsynchronized traffic such as the resolver's root priming query. + """ + last = -1 + + def stable() -> bool: + nonlocal last + previous, last = last, tcp_requests_received(ns) + return previous == last + + isctest.run.retry_with_timeout(stable, timeout=timeout) + return last + + def test_tcp_request_statistics( ns1: NamedInstance, ns2: NamedInstance, ns3: NamedInstance, ns4: NamedInstance ) -> None: @@ -378,21 +397,19 @@ def test_tcp_request_statistics( isctest.log.info("checking TCP request statistics (resolver)") msg = isctest.query.create("txt.example.", "A") - isctest.query.udp(msg, ns3.ip) - time.sleep(1) + isctest.query.udp(msg, ns3.ip, expected_rcode=dns.rcode.NXDOMAIN) - ns1_tcp_after_resolver = tcp_requests_received(ns1) - ns2_tcp_after_resolver = tcp_requests_received(ns2) + ns1_tcp_after_resolver = wait_for_stable_tcp_requests(ns1) + ns2_tcp_after_resolver = wait_for_stable_tcp_requests(ns2) assert ns1_tcp < ns1_tcp_after_resolver assert ns2_tcp == ns2_tcp_after_resolver isctest.log.info("checking TCP request statistics (forwarder)") msg = isctest.query.create("txt.example.", "A") - isctest.query.udp(msg, ns4.ip) - time.sleep(1) + isctest.query.udp(msg, ns4.ip, expected_rcode=dns.rcode.NXDOMAIN) - ns1_tcp_after_forwarder = tcp_requests_received(ns1) - ns2_tcp_after_forwarder = tcp_requests_received(ns2) + ns1_tcp_after_forwarder = wait_for_stable_tcp_requests(ns1) + ns2_tcp_after_forwarder = wait_for_stable_tcp_requests(ns2) assert ns1_tcp_after_resolver == ns1_tcp_after_forwarder assert ns2_tcp_after_resolver < ns2_tcp_after_forwarder