From 86c254f46b0581dcd859f6bbba4f5bc4d96677a0 Mon Sep 17 00:00:00 2001 From: Sam Ebstein Date: Mon, 9 Dec 2024 09:46:46 -0800 Subject: [PATCH 1/2] locust/main.py: add max_run_time logic --- locust/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/locust/main.py b/locust/main.py index 67b278f8a1..8fbd3a9eb0 100644 --- a/locust/main.py +++ b/locust/main.py @@ -477,6 +477,22 @@ def ensure_user_class_name(config): ) sys.exit(1) + if options.max_run_time: + if options.worker: + logger.info("--max-run-time specified for a worker node will be ignored.") + try: + options.max_run_time = parse_timespan(options.max_run_time) + except ValueError: + logger.error( + f"Invalid --max-run-time argument ({options.max_run_time}), accepted formats are for example 120, 120s, 2m, 3h, 3h30m10s." + ) + sys.exit(1) + if options.run_time is None or options.max_run_time < options.run_time: + logger.info( + f"Applying --max-run-time cap: run time reduced from {options.run_time if options.run_time else 'undefined'} to {options.max_run_time}." + ) + options.run_time = options.max_run_time + if options.csv_prefix: base_csv_file = os.path.basename(options.csv_prefix) base_csv_dir = options.csv_prefix[: -len(base_csv_file)] From aec722b67b84856c124c1cf84ff33daf660efdfd Mon Sep 17 00:00:00 2001 From: Sam Ebstein Date: Mon, 9 Dec 2024 10:26:35 -0800 Subject: [PATCH 2/2] locust/argument_parser.py: add --max-run-time arg --- locust/argument_parser.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/locust/argument_parser.py b/locust/argument_parser.py index 827a2f880e..f158bba521 100644 --- a/locust/argument_parser.py +++ b/locust/argument_parser.py @@ -416,6 +416,12 @@ def setup_parser_arguments(parser): help="Stop after the specified amount of time, e.g. (300s, 20m, 3h, 1h30m, etc.). Only used together with --headless or --autostart. Defaults to run forever.", env_var="LOCUST_RUN_TIME", ) + parser.add_argument( + "--max-run-time", + metavar="