Only waithing when there is something to wait for

This commit is contained in:
Pünkösd Marcell 2020-10-23 16:28:20 +02:00
parent abd63a7fad
commit 837d3462be

View File

@ -233,20 +233,23 @@ def main():
print("Running benchmark...") print("Running benchmark...")
benchmark_results = run_benchmark(args.workers, args.timeout, args.file) 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 # Wait for inflight messages for a little
total_successful_uploads = len([req for req in benchmark_results if req.upload_status_code == 200]) total_successful_uploads = len([req for req in benchmark_results if req.upload_status_code == 200])
all_arrived = False all_arrived = alerts_arrived_queue.qsize() >= total_successful_uploads
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) if (not all_arrived) and (args.inflight_timeout > 0):
waited_for_inflight = time.time() - waiting_started print("Waiting for inflight MQTT messages to arrive...")
print(f"Waited a total {waited_for_inflight} seconds")
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: if not all_arrived:
print("WARNING: Not all MQTT Messages arrived!") print("WARNING: Not all MQTT Messages arrived!")