Skip to content

Commit

Permalink
Merge pull request #2685 from Sawiq/master
Browse files Browse the repository at this point in the history
Allow worker process to run with --run-time specified, just log a warning
  • Loading branch information
cyberw authored Apr 22, 2024
2 parents 1a94044 + 9faddd6 commit a89d334
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions locust/util/timespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,8 +18,7 @@ def parse_timespan(time_str):
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())

0 comments on commit a89d334

Please sign in to comment.