]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Re-fetch traffic counters until they converge
authorMichal Nowak <mnowak@isc.org>
Tue, 2 Jun 2026 14:53:25 +0000 (14:53 +0000)
committerMichal Nowak <mnowak@isc.org>
Wed, 10 Jun 2026 19:15:09 +0000 (19:15 +0000)
The counters update asynchronously, so a single snapshot can lag.

Assisted-by: Claude:claude-opus-4-8
bin/tests/system/statschannel/generic.py

index 02a7eea38306b3e663a4dc2d4ed6e843a6251d36..874baf97d1aeef442afb31bbf134897100b09bb8 100644 (file)
@@ -188,6 +188,16 @@ def check_traffic(data, expected):
     assert ordered_data == ordered_expected
 
 
+def wait_for_traffic(fetch_traffic, statsip, statsport, expected):
+    # named updates the counters asynchronously, so a snapshot taken right
+    # after the query may lag; re-fetch until it matches (or time out).
+    def fetch_and_check():
+        check_traffic(fetch_traffic(statsip, statsport), expected)
+        return True
+
+    isctest.run.retry_with_timeout(fetch_and_check, timeout=10)
+
+
 def test_traffic(fetch_traffic, **kwargs):
     statsip = kwargs["statsip"]
     statsport = kwargs["statsport"]
@@ -200,36 +210,28 @@ def test_traffic(fetch_traffic, **kwargs):
     ans = isctest.query.udp(msg, statsip, attempts=1)
     isctest.check.noerror(ans)
     update_expected(exp, "dns-udp-responses-sizes-sent-ipv4", ans)
-    data = fetch_traffic(statsip, statsport)
-
-    check_traffic(data, exp)
+    wait_for_traffic(fetch_traffic, statsip, statsport, exp)
 
     msg = create_msg("long.example.", "TXT")
     update_expected(exp, "dns-udp-requests-sizes-received-ipv4", msg)
     ans = isctest.query.udp(msg, statsip, attempts=1)
     isctest.check.noerror(ans)
     update_expected(exp, "dns-udp-responses-sizes-sent-ipv4", ans)
-    data = fetch_traffic(statsip, statsport)
-
-    check_traffic(data, exp)
+    wait_for_traffic(fetch_traffic, statsip, statsport, exp)
 
     msg = create_msg("short.example.", "TXT")
     update_expected(exp, "dns-tcp-requests-sizes-received-ipv4", msg)
     ans = isctest.query.tcp(msg, statsip, attempts=1)
     isctest.check.noerror(ans)
     update_expected(exp, "dns-tcp-responses-sizes-sent-ipv4", ans)
-    data = fetch_traffic(statsip, statsport)
-
-    check_traffic(data, exp)
+    wait_for_traffic(fetch_traffic, statsip, statsport, exp)
 
     msg = create_msg("long.example.", "TXT")
     update_expected(exp, "dns-tcp-requests-sizes-received-ipv4", msg)
     ans = isctest.query.tcp(msg, statsip, attempts=1)
     isctest.check.noerror(ans)
     update_expected(exp, "dns-tcp-responses-sizes-sent-ipv4", ans)
-    data = fetch_traffic(statsip, statsport)
-
-    check_traffic(data, exp)
+    wait_for_traffic(fetch_traffic, statsip, statsport, exp)
 
 
 def test_rtt(fetch_views, **kwargs):