diff --git a/opl/args.py b/opl/args.py index d63b61a..0e0771f 100644 --- a/opl/args.py +++ b/opl/args.py @@ -314,6 +314,13 @@ def add_locust_opts(parser): default=int(os.getenv("LOCUST_STOP_TIMEOUT", 10)), help="Locust stop timeout (also use env variable LOCUST_STOP_TIMEOUT)", ) + parser.add_argument( + "--locust-wait-for-worker-timeout", + dest="worker_wait_timeout" + type=int, + default=int(os.getenv("LOCUST_WAIT_FOR_WORKER_TIMEOUT", 120)), + help="Locust timeout [s] for waiting until worker pods are ready. (also use env variable LOCUST_WAIT_FOR_WORKER_TIMEOUT)", + ) # Our test specific parameters parser.add_argument( diff --git a/opl/locust.py b/opl/locust.py index 3fa5a69..a9998a8 100644 --- a/opl/locust.py +++ b/opl/locust.py @@ -93,6 +93,7 @@ def run_locust(args, status_data, test_set, new_stats=False, summary_only=False) env.runner.spawn_rate = args.hatch_rate + time_spent_waiting = 0 while len(env.runner.clients.ready) < args.expect_workers: logging.info( "Waiting for worker to become ready, %s of %s - %s", @@ -101,6 +102,11 @@ def run_locust(args, status_data, test_set, new_stats=False, summary_only=False) ",".join([i.state for i in env.runner.clients.values()]), ) time.sleep(1) + time_spent_waiting += 1 + if time_spent_waiting >= args.worker_wait_timeout: + raise TimeoutError( + f"Timed out waiting for Locust workers to get ready: {len(env.runner.clients.ready)} out of {args.expect_workers}" + ) # Start the test logging.info("Starting master Locust runer")