From ff30c7fcb71c6a0368e257a09c7ae936de06b438 Mon Sep 17 00:00:00 2001 From: aathan Date: Sat, 20 Aug 2022 11:00:24 -0700 Subject: [PATCH 1/2] Example had inconsistent labeling The example inconsistently labeled worker and master in the comments and/or registered the wrong messages to the wrong runners. --- docs/running-distributed.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/running-distributed.rst b/docs/running-distributed.rst index cd9ecbb6aa..e3b0acb0e5 100644 --- a/docs/running-distributed.rst +++ b/docs/running-distributed.rst @@ -90,21 +90,21 @@ 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 worker receives a message of type 'test_users' + # Fired when the master 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 master receives a message of type 'acknowledge_users' + # Fired when the worker 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 not isinstance(environment.runner, MasterRunner): + if isinstance(environment.runner, MasterRunner): environment.runner.register_message('test_users', setup_test_users) - if not isinstance(environment.runner, WorkerRunner): + if isinstance(environment.runner, WorkerRunner): environment.runner.register_message('acknowledge_users', on_acknowledge) @events.test_start.add_listener From fd5a255bcd24bc6c43f7cab77e2530626f5c00ed Mon Sep 17 00:00:00 2001 From: aathan Date: Sat, 20 Aug 2022 11:13:55 -0700 Subject: [PATCH 2/2] Updated to reflect examples 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/ --- docs/running-distributed.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/running-distributed.rst b/docs/running-distributed.rst index e3b0acb0e5..15f45af3a5 100644 --- a/docs/running-distributed.rst +++ b/docs/running-distributed.rst @@ -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"},