From 437287fadc2cb741a495a3e6f35607d387342e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?373=5B=C3=98=5D=E2=84=A2?= <151577046+ccclxxiii@users.noreply.github.com> Date: Sun, 22 Feb 2026 15:55:03 +0000 Subject: [PATCH 1/3] feat(tests): add optional benchmark cooldown between iterations --- cmdeploy/src/cmdeploy/tests/plugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index 60d27efc..257533e2 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -92,7 +92,7 @@ def cm_data(request): @pytest.fixture def benchmark(request): - def bench(func, num, name=None, reportfunc=None): + def bench(func, num, name=None, reportfunc=None, cooldown=0.0): if name is None: name = func.__name__ durations = [] @@ -100,6 +100,9 @@ def benchmark(request): now = time.time() func() durations.append(time.time() - now) + if cooldown > 0 and i + 1 < num: + # Keep post-run cooldown out of measured benchmark duration. + time.sleep(cooldown) durations.sort() request.config._benchresults[name] = (reportfunc, durations) From 193624e522bc9f456e81d7ff7bc7ba6283d3cac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?373=5B=C3=98=5D=E2=84=A2?= <151577046+ccclxxiii@users.noreply.github.com> Date: Sun, 22 Feb 2026 15:58:21 +0000 Subject: [PATCH 2/3] fix(benchmark): add rate-limit refill cooldown for send_10_receive_10 and avoid fixture signature mismatch --- cmdeploy/src/cmdeploy/tests/online/benchmark.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmdeploy/src/cmdeploy/tests/online/benchmark.py b/cmdeploy/src/cmdeploy/tests/online/benchmark.py index 01de017b..eca7751c 100644 --- a/cmdeploy/src/cmdeploy/tests/online/benchmark.py +++ b/cmdeploy/src/cmdeploy/tests/online/benchmark.py @@ -1,3 +1,4 @@ +import time def test_tls_imap(benchmark, imap): def imap_connect(): imap.connect() @@ -47,7 +48,7 @@ class TestDC: benchmark(dc_ping_pong, 5) - def test_send_10_receive_10(self, benchmark, cmfactory, lp): + def test_send_10_receive_10(self, request, cmfactory, chatmail_config, lp): ac1, ac2 = cmfactory.get_online_accounts(2) chat = cmfactory.get_accepted_chat(ac1, ac2) @@ -57,4 +58,16 @@ class TestDC: for i in range(10): ac2._evtracker.wait_next_incoming_message() - benchmark(dc_send_10_receive_10, 5) + per_minute = max(chatmail_config.max_user_send_per_minute, 1) + cooldown = chatmail_config.max_user_send_burst_size * 60 / per_minute + durations = [] + num = 5 + for i in range(num): + now = time.time() + dc_send_10_receive_10() + durations.append(time.time() - now) + if i + 1 < num: + # Keep post-run cooldown out of measured benchmark duration. + time.sleep(cooldown) + durations.sort() + request.config._benchresults["dc_send_10_receive_10"] = (None, durations) From 7b5b180b4b47904245c4d11a83ad10bd27da7107 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 22 Feb 2026 18:26:15 +0100 Subject: [PATCH 3/3] refactor(benchmark): move rate-limit cooldown to benchmark fixture --- cmdeploy/src/cmdeploy/tests/online/benchmark.py | 16 ++-------------- cmdeploy/src/cmdeploy/tests/plugin.py | 6 +++++- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/cmdeploy/src/cmdeploy/tests/online/benchmark.py b/cmdeploy/src/cmdeploy/tests/online/benchmark.py index eca7751c..c65292b5 100644 --- a/cmdeploy/src/cmdeploy/tests/online/benchmark.py +++ b/cmdeploy/src/cmdeploy/tests/online/benchmark.py @@ -48,7 +48,7 @@ class TestDC: benchmark(dc_ping_pong, 5) - def test_send_10_receive_10(self, request, cmfactory, chatmail_config, lp): + def test_send_10_receive_10(self, benchmark, cmfactory, lp): ac1, ac2 = cmfactory.get_online_accounts(2) chat = cmfactory.get_accepted_chat(ac1, ac2) @@ -58,16 +58,4 @@ class TestDC: for i in range(10): ac2._evtracker.wait_next_incoming_message() - per_minute = max(chatmail_config.max_user_send_per_minute, 1) - cooldown = chatmail_config.max_user_send_burst_size * 60 / per_minute - durations = [] - num = 5 - for i in range(num): - now = time.time() - dc_send_10_receive_10() - durations.append(time.time() - now) - if i + 1 < num: - # Keep post-run cooldown out of measured benchmark duration. - time.sleep(cooldown) - durations.sort() - request.config._benchresults["dc_send_10_receive_10"] = (None, durations) + benchmark(dc_send_10_receive_10, 5, cooldown="auto") diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index 257533e2..3f6a4333 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -91,10 +91,14 @@ def cm_data(request): @pytest.fixture -def benchmark(request): +def benchmark(request, chatmail_config): def bench(func, num, name=None, reportfunc=None, cooldown=0.0): if name is None: name = func.__name__ + if cooldown == "auto": + per_minute = max(chatmail_config.max_user_send_per_minute, 1) + cooldown = chatmail_config.max_user_send_burst_size * 60 / per_minute + durations = [] for i in range(num): now = time.time()