Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_stop is fired twice when Locust is running in –master/worker mode #1638

Closed
12monkeys-stack opened this issue Nov 27, 2020 · 5 comments
Labels

Comments

@12monkeys-stack
Copy link

when 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...
@cyberw
Copy link
Collaborator

cyberw commented Nov 30, 2020

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?

@cyberw cyberw added the bug label Dec 1, 2020
@heyman
Copy link
Member

heyman commented Dec 1, 2020

This sounds like a bug to me. I'll see if I can produce a test (and a fix) for it.

@heyman
Copy link
Member

heyman commented Dec 1, 2020

PR here: #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.

@cyberw
Copy link
Collaborator

cyberw commented Dec 1, 2020

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

@cyberw cyberw closed this as completed Dec 1, 2020
@ludeknovy
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants