From ff10589417c85f10c7995c8a40f686fd7f6466b3 Mon Sep 17 00:00:00 2001 From: Joey Wilhelm Date: Tue, 10 Sep 2024 09:41:48 -0600 Subject: [PATCH 1/3] fix: Add more worker info to LocalRunner for parity with others --- locust/runners.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/locust/runners.py b/locust/runners.py index 6fe641d1b7..ad7bc1e710 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -437,6 +437,8 @@ 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 + self.workers = [self] # 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 From 9168bcfd18bea3de1a00fc8f733b457eb948c6fb Mon Sep 17 00:00:00 2001 From: Joey Wilhelm Date: Wed, 11 Sep 2024 09:54:25 -0600 Subject: [PATCH 2/3] fix: Remove workers from LocalRunner --- locust/runners.py | 1 - 1 file changed, 1 deletion(-) diff --git a/locust/runners.py b/locust/runners.py index ad7bc1e710..e75f043478 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -438,7 +438,6 @@ def __init__(self, environment) -> None: self.worker_index = 0 self.client_id = socket.gethostname() + "_" + uuid4().hex self.worker_count = 1 - self.workers = [self] # 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 From a019463b56a44790ad97c7f18c1535c9745107cf Mon Sep 17 00:00:00 2001 From: Joey Wilhelm Date: Wed, 11 Sep 2024 09:54:46 -0600 Subject: [PATCH 3/3] fix: Fix the custom_messages example to work with LocalRunner --- examples/custom_messages.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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: