Skip to content

Commit

Permalink
feat(Locust opl): Add timeout mechanism when waiting for Locust workers
Browse files Browse the repository at this point in the history
  • Loading branch information
Smejky338 committed Sep 16, 2024
1 parent 76c5b1e commit 20b988e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions opl/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions opl/locust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand Down

0 comments on commit 20b988e

Please sign in to comment.