]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use AnsInstance fixture in dispatch test 12241/head
authorNicki Křížek <nicki@isc.org>
Fri, 12 Jun 2026 11:44:10 +0000 (13:44 +0200)
committerNicki Křížek <nicki@isc.org>
Tue, 16 Jun 2026 07:34:25 +0000 (09:34 +0200)
Replace manual ans.run parsing with the ans4 fixture.

Assisted-by: Claude:claude-fable-5
bin/tests/system/dispatch/tests_tcponly.py

index 373ee56017c83aa936dc862055620bbf28c4726c..a4d30c3429bdec2b2f239e5389d618755c6ce507 100644 (file)
@@ -27,13 +27,12 @@ pytestmark = pytest.mark.extra_artifacts(
 )
 
 
-def _count_received(path, qname, protocol):
+def _count_received(ans, qname, protocol):
     pattern = Re(rf"Received {escape(qname)}/IN/A .* \({protocol}\)$")
-    with open(path, encoding="utf-8") as fh:
-        return sum(1 for line in fh if pattern.search(line.rstrip()))
+    return len(ans.log.grep(pattern))
 
 
-def test_tcponly_fallback():
+def test_tcponly_fallback(ans4):
     """
     A resolver must fall back to TCP after repeated UDP timeouts to the
     same authoritative server.  ans4 drops every UDP query and answers
@@ -51,7 +50,7 @@ def test_tcponly_fallback():
     )
     assert str(rdataset[0]) == "127.0.0.1"
 
-    udp = _count_received("ans4/ans.run", "foo.tcp-only", "UDP")
-    tcp = _count_received("ans4/ans.run", "foo.tcp-only", "TCP")
+    udp = _count_received(ans4, "foo.tcp-only", "UDP")
+    tcp = _count_received(ans4, "foo.tcp-only", "TCP")
     assert udp == 2, f"expected exactly 2 UDP queries, got {udp}"
     assert tcp == 1, f"expected exactly 1 TCP query, got {tcp}"