when I run locust in 鈥搈aster/worker mode锛宼est_stop is fired twice, but test_start is fired once.
my user class:
class MyUser(User):
wait_time = constant_pacing(1)
@task
def my_task(self):
print("executing my_task")
@events.test_start.add_listener
def on_test_start(**kwargs):
print("on_test_start")
@events.test_stop.add_listener
def on_test_stop(**kwargs):
print("on_test_stop")
def on_start(self):
print("start task")
def on_stop(self):
print("stop task")
the test command:
master_cmd = "locust -f MyLocust.py --host 127.0.0.1 -u 2 -r 1 -t 5s --master --expect-workers 1 --headless " \
"--skip-log-setup --loglevel ERROR --logfile test.log"
worker_cmd = "locust -f MyLocust.py --worker"
process1 = subprocess.Popen(master_cmd)
process2 = subprocess.Popen(worker_cmd)
process1.wait()
the log information:
[2020-11-27 10:21:23,590] DESKTOP-200810/INFO/locust.main: Starting Locust 1.3.0
[2020-11-27 10:21:24,592] DESKTOP-200810/INFO/locust.runners: Spawning 2 users at the rate 1 users/s (0 users already running)...
on_test_start
start task
executing my_task
[2020-11-27 10:21:25,592] DESKTOP-200810/INFO/locust.runners: All users spawned: MyUser: 2 (0 already running)
executing my_task
start task
executing my_task
executing my_task
executing my_task
executing my_task
executing my_task
executing my_task
executing my_task
on_test_stop
[2020-11-27 10:21:29,592] DESKTOP-200810/INFO/locust.runners: Got quit message from master, shutting down...
executing my_task
[2020-11-27 10:21:29,592] DESKTOP-200810/INFO/locust.runners: Stopping 2 users
executing my_task
[2020-11-27 10:21:29,593] DESKTOP-200810/INFO/locust.runners: 2 Users have been stopped
stop task
[2020-11-27 10:21:29,593] DESKTOP-200810/INFO/locust.main: Running teardowns...
stop task
[2020-11-27 10:21:29,593] DESKTOP-200810/INFO/locust.main: Shutting down (exit code 0), bye.
on_test_stop
[2020-11-27 10:21:29,593] DESKTOP-200810/INFO/locust.main: Cleaning up runner...
This behaviour relates to quitting test_stop.fire being called both here:
https://github.com/locustio/locust/blob/master/locust/runners.py#L575
and here:
https://github.com/locustio/locust/blob/master/locust/runners.py#L581
I'm not sure what the best way to fix this is. @heyman You originally wrote the code, maybe you have an opinion?
This sounds like a bug to me. I'll see if I can produce a test (and a fix) for it.
PR here: https://github.com/locustio/locust/pull/1641
The whole machinery keeping track of Runners and their states could probably use some rework at some point. The current code has evolved over time with patch upon patch and feels a bit brittle at the moment.
Should be fixed now. If you can't wait for it to make it into a release, you can run from latest master:
pip3 install -e git://github.com/locustio/locust.git@master#egg=locust
I did a quick retest with two workers on git://github.com/locustio/locust.git@master#egg=locust and it looks good. Thanks for quick fix.
Most helpful comment
PR here: https://github.com/locustio/locust/pull/1641
The whole machinery keeping track of Runners and their states could probably use some rework at some point. The current code has evolved over time with patch upon patch and feels a bit brittle at the moment.