Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Locust opl): Add timeout mechanism when waiting for Locust workers #139

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading