]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
fixup! Port the long TCP stream test to Python
authorNicki Křížek <nicki@isc.org>
Thu, 11 Jun 2026 11:36:44 +0000 (11:36 +0000)
committerNicki Křížek <nicki@isc.org>
Thu, 11 Jun 2026 11:45:56 +0000 (13:45 +0200)
Assisted-by: Claude:claude-fable-5
bin/tests/system/tcp/tests_tcp.py

index b788a96d62ce31a40b7ed450f74e6bbf90c92462..8472ece8fc075f87c6d2f2079c17df895bbec0a3 100644 (file)
@@ -11,7 +11,7 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-from collections.abc import Iterable
+from collections.abc import Iterable, Iterator
 from types import TracebackType
 from typing import NamedTuple
 
@@ -479,9 +479,27 @@ def test_tcp_high_water(named_port: int, ns5: NamedInstance) -> None:
     asyncio.run(run())
 
 
+def debug_level(ns: NamedInstance) -> int:
+    status = ns.rndc("status").out
+    matches = status.grep("debug level:")
+    assert matches, f"'debug level' not found in rndc status:\n{status}"
+    return int(matches[0].string.partition(":")[2])
+
+
+@contextlib.contextmanager
+def temporary_trace_level(ns: NamedInstance, level: int) -> Iterator[None]:
+    """Lower the debug level for a noisy section, then restore the default."""
+    prev_level = debug_level(ns)
+    ns.rndc(f"trace {level}")
+    try:
+        yield
+    finally:
+        # Don't mask an in-flight test failure if named has died.
+        ns.rndc(f"trace {prev_level}", raise_on_exception=False)
+
+
 def test_long_tcp_messages(named_port: int, ns1: NamedInstance) -> None:
     isctest.log.info("checking that BIND 9 doesn't crash on long TCP messages")
-    ns1.rndc("trace 1")
     stream_bytes = 6 * 1024 * 1024
     msg = isctest.query.create(
         "isc.org.",
@@ -492,7 +510,10 @@ def test_long_tcp_messages(named_port: int, ns1: NamedInstance) -> None:
         ad=False,
         message_id=1,
     )
-    asyncio.run(send_long_tcp_stream(ns1.ip, named_port, msg, stream_bytes))
 
-    msg = isctest.query.create("txt.example.", "A")
-    isctest.query.tcp(msg, ns1.ip)
+    # Avoid logging the huge query stream at the default debug level.
+    with temporary_trace_level(ns1, 1):
+        asyncio.run(send_long_tcp_stream(ns1.ip, named_port, msg, stream_bytes))
+
+        msg = isctest.query.create("txt.example.", "A")
+        isctest.query.tcp(msg, ns1.ip)