From 30386e69adcdd12cb4c7d2c14ec7ff55a4cea904 Mon Sep 17 00:00:00 2001 From: Piotr Sawicki Date: Sun, 21 Apr 2024 01:00:53 +0200 Subject: [PATCH 1/2] Removed an error upon providing run_time for a worker process --- locust/main.py | 3 +-- locust/util/timespan.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/locust/main.py b/locust/main.py index 38550ab618..491001da01 100644 --- a/locust/main.py +++ b/locust/main.py @@ -433,8 +433,7 @@ def ensure_user_class_name(config): if options.run_time: if options.worker: - logger.error("--run-time should be specified on the master node, and not on worker nodes") - sys.exit(1) + logger.info("--run-time specified for a worker node will be ignored.") try: options.run_time = parse_timespan(options.run_time) except ValueError: diff --git a/locust/util/timespan.py b/locust/util/timespan.py index 7fdc607c4d..a3963bd9f6 100644 --- a/locust/util/timespan.py +++ b/locust/util/timespan.py @@ -2,7 +2,7 @@ from datetime import timedelta -def parse_timespan(time_str): +def parse_timespan(time_str) -> int: """ Parse a string representing a time span and return the number of seconds. Valid formats are: 20, 20s, 3m, 2h, 1h20m, 3h30m10s, etc. From 9faddd639903f19703b9105a63b8325b236f673f Mon Sep 17 00:00:00 2001 From: Piotr Sawicki Date: Mon, 22 Apr 2024 22:17:30 +0200 Subject: [PATCH 2/2] Removed line with variable reassignment --- locust/util/timespan.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/locust/util/timespan.py b/locust/util/timespan.py index a3963bd9f6..910ad89be4 100644 --- a/locust/util/timespan.py +++ b/locust/util/timespan.py @@ -18,8 +18,7 @@ def parse_timespan(time_str) -> int: parts = timespan_regex.match(time_str) if not parts: raise ValueError("Invalid time span format. Valid formats: 20, 20s, 3m, 2h, 1h20m, 3h30m10s, etc.") - parts = parts.groupdict() - time_params = {name: int(value) for name, value in parts.items() if value} + time_params = {name: int(value) for name, value in parts.groupdict().items() if value} if not time_params: raise ValueError("Invalid time span format. Valid formats: 20, 20s, 3m, 2h, 1h20m, 3h30m10s, etc.") return int(timedelta(**time_params).total_seconds())