From 837d3462be74306ad4552466e1722f64840571ba Mon Sep 17 00:00:00 2001 From: marcsello Date: Fri, 23 Oct 2020 16:28:20 +0200 Subject: [PATCH] Only waithing when there is something to wait for --- benchmark3.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/benchmark3.py b/benchmark3.py index db8666f..4ce74a5 100644 --- a/benchmark3.py +++ b/benchmark3.py @@ -233,20 +233,23 @@ def main(): print("Running benchmark...") benchmark_results = run_benchmark(args.workers, args.timeout, args.file) - print("Waiting for inflight MQTT messages to arrive...") + # Wait for inflight messages for a little - total_successful_uploads = len([req for req in benchmark_results if req.upload_status_code == 200]) - all_arrived = False - waiting_started = time.time() - for _ in range(int(args.inflight_timeout * 1000)): - if alerts_arrived_queue.qsize() >= total_successful_uploads: - all_arrived = True - break + all_arrived = alerts_arrived_queue.qsize() >= total_successful_uploads - time.sleep(0.001) - waited_for_inflight = time.time() - waiting_started - print(f"Waited a total {waited_for_inflight} seconds") + if (not all_arrived) and (args.inflight_timeout > 0): + print("Waiting for inflight MQTT messages to arrive...") + + waiting_started = time.time() + for _ in range(int(args.inflight_timeout * 1000)): + if alerts_arrived_queue.qsize() >= total_successful_uploads: + all_arrived = True + break + + time.sleep(0.001) + waited_for_inflight = time.time() - waiting_started + print(f"Waited a total {waited_for_inflight} seconds") if not all_arrived: print("WARNING: Not all MQTT Messages arrived!")