test_stop is fired twice when Locust is running in –master/worker mode
See original GitHub issuewhen I run locust in –master/worker mode,test_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...
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Two test_stop events triggered when --run-time expires #1421
The stop() method is invoked twice, once for the run-time expiration and again when the last worker quits. Both invocations trigger the on_stop ......
Read more >Distributed load generation — Locust 2.14.0 documentation
To do this, you start one instance of Locust in master mode using the --master flag and multiple worker instances using the --worker...
Read more >Is there an event hook in worker node fired after tests stoped?
1 Answer 1 ... How about test_start / test_stop? https://docs.locust.io/en/stable/writing-a-locustfile.html#test-start-and-test-stop.
Read more >Load Testing Using Locust.io - Medium
It's not fired again if the number of users changes during a test. Meanwhile, test_stop fires when a load test is stopped. Running...
Read more >Quick Tutorial on Locust
To run Locust, we need a “web server” whose performance we want to test. ... def on_start(self): """on_start is called when a Locust...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.