# 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
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.",
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)