Skip to content

Commit

Permalink
Updated to reflect examples
Browse files Browse the repository at this point in the history
I saw similar code in examples/ directory that has the master/worker roles swapped from my original fix. The original code is inconsistent and it wasn't clear which was intended as worker vs master, but this new commit matches what's in examples/
  • Loading branch information
aathan authored Aug 20, 2022
1 parent ff30c7f commit fd5a255
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/running-distributed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,26 @@ order to coordinate data. This can be easily accomplished with custom messages u
from locust import events
from locust.runners import MasterRunner, WorkerRunner
# Fired when the master receives a message of type 'test_users'
# Fired when the worker receives a message of type 'test_users'
def setup_test_users(environment, msg, **kwargs):
for user in msg.data:
print(f"User {user['name']} received")
environment.runner.send_message('acknowledge_users', f"Thanks for the {len(msg.data)} users!")
# Fired when the worker receives a message of type 'acknowledge_users'
# Fired when the master receives a message of type 'acknowledge_users'
def on_acknowledge(msg, **kwargs):
print(msg.data)
@events.init.add_listener
def on_locust_init(environment, **_kwargs):
if isinstance(environment.runner, MasterRunner):
if not isinstance(environment.runner, MasterRunner):
environment.runner.register_message('test_users', setup_test_users)
if isinstance(environment.runner, WorkerRunner):
if not isinstance(environment.runner, WorkerRunner):
environment.runner.register_message('acknowledge_users', on_acknowledge)
@events.test_start.add_listener
def on_test_start(environment, **_kwargs):
if not isinstance(environment.runner, MasterRunner):
if not isinstance(environment.runner, WorkerRunner):
users = [
{"name": "User1"},
{"name": "User2"},
Expand Down

0 comments on commit fd5a255

Please sign in to comment.