diff --git a/cmdeploy/src/cmdeploy/tests/online/benchmark.py b/cmdeploy/src/cmdeploy/tests/online/benchmark.py index 01de017b..c65292b5 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() @@ -57,4 +58,4 @@ class TestDC: for i in range(10): ac2._evtracker.wait_next_incoming_message() - benchmark(dc_send_10_receive_10, 5) + 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 60d27efc..3f6a4333 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -91,15 +91,22 @@ def cm_data(request): @pytest.fixture -def benchmark(request): - def bench(func, num, name=None, reportfunc=None): +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() 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)