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()