diff --git a/examples/custom_messages.py b/examples/custom_messages.py index 9dd1f6890e..357203aab3 100644 --- a/examples/custom_messages.py +++ b/examples/custom_messages.py @@ -1,5 +1,5 @@ from locust import HttpUser, between, events, task -from locust.runners import MasterRunner, WorkerRunner +from locust.runners import LocalRunner, MasterRunner, WorkerRunner import gevent @@ -44,8 +44,12 @@ def on_test_start(environment, **_kwargs): worker_count = environment.runner.worker_count chunk_size = int(len(users) / worker_count) + if isinstance(environment.runner, LocalRunner): + workers = [environment.runner] + else: + workers = [environment.runner.clients] - for i, worker in enumerate(environment.runner.clients): + for i, worker in enumerate(workers): start_index = i * chunk_size if i + 1 < worker_count: diff --git a/locust/runners.py b/locust/runners.py index 6fe641d1b7..e75f043478 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -437,6 +437,7 @@ def __init__(self, environment) -> None: # but it makes it easier to write tests that work for both local and distributed runs self.worker_index = 0 self.client_id = socket.gethostname() + "_" + uuid4().hex + self.worker_count = 1 # Only when running in standalone mode (non-distributed) self._local_worker_node = WorkerNode(id="local") self._local_worker_node.user_classes_count = self.user_classes_count