From f758ffe0aa9490b504f9a4ae5d9c8a7180c41868 Mon Sep 17 00:00:00 2001 From: Michal Nowak Date: Tue, 2 Jun 2026 14:53:25 +0000 Subject: [PATCH] Re-fetch traffic counters until they converge The counters update asynchronously, so a single snapshot can lag. Assisted-by: Claude:claude-opus-4-8 --- bin/tests/system/statschannel/generic.py | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bin/tests/system/statschannel/generic.py b/bin/tests/system/statschannel/generic.py index 02a7eea383..874baf97d1 100644 --- a/bin/tests/system/statschannel/generic.py +++ b/bin/tests/system/statschannel/generic.py @@ -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):