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

on_master_stop_hatching is not triggered on master when hatching terminates #1295

Closed
endejoli opened this issue Mar 23, 2020 · 4 comments
Closed
Labels

Comments

@endejoli
Copy link

endejoli commented Mar 23, 2020

Describe the bug

When the hatching terminates on_master_stop_hatching is not triggered on the master but on_master_start_hatching triggers just fine

Locustfile.py

from locust import Locust, HttpLocust, TaskSet, task, between, events
import json,time
class UserBehavior(TaskSet):

@task(1)    
def create_item(self):
    headers = {'content-type': 'application/json'}
    self.client.post("/create",data= json.dumps({
      "title": "PT",
      "description": "This  is used for performance test"
}), 
headers=headers, 
name = "Create a new item")

@task(1)    
def list_items(self):
    headers = {'content-type': 'application/json'}
    self.client.get("/list", 
    headers=headers, 
    name = "List all items")

class WebsiteUser(HttpLocust):
def setup(self):
print("Hello.. I am just starting the test")
task_set = UserBehavior
wait_time = between(3, 25)
def on_master_stop_hatching():
print("")
print("I am stopping on master")
print("
")
events.master_stop_hatching += on_master_stop_hatching

Master

locust --host=https://test.com --master --no-web --expect-slaves=1 -c 10 -r 10 --run-time=10s

Slave

locust -f locustfile.py --slave

Expected behavior

Master console should print


"I am stopping on master"

Actual behavior

Nothing gets printed

Steps to reproduce

  1. Please use the above locustfile and commands to reproduce the same

Environment

  • OS: Windows
  • Python version: 3.7.4
  • Locust version: 0.14.5
@endejoli endejoli added the bug label Mar 23, 2020
@Trouv
Copy link
Contributor

Trouv commented Apr 11, 2020

Hey I'm new here.

I'm not sure if this is by design. When you run using --run-time, locust will "quit" on the master process after the specified time instead of "stop". As far as I can tell, the master process only "stop"s when you click stop in the web browser mode. The docstring mentions this:

*master_stop_hatching* is fired when terminate the hatching process on the master.

This event is especially useful to detect when the 'stop' button is clicked on the web ui.

So, if you want to know when the run time is over, you could use the quitting EventHook.
Or if you wanted to know when the all of the locusts are spawned, you should use the hatch_complete EventHook.

It does seem a bit weird though that the locust_stop_hatching event is fired on the worker processes but master_stop_hatching isn't on the master process when the time runs out.

@Trouv
Copy link
Contributor

Trouv commented Apr 11, 2020

It seems this will be addressed in 1.0.0

This event and locust_stop_hatching have been replaced by test_stop in #1309, and the event runs just fine when running the 1.0.0 version of this script/commands. Actually, it runs twice!

@heyman
Copy link
Member

heyman commented Apr 12, 2020

Actually, it runs twice!

Oh, that's a bug which is now fixed (18fddf9)

@cyberw
Copy link
Collaborator

cyberw commented Jun 6, 2020

This is fixed I think?

@cyberw cyberw closed this as completed Jun 6, 2020
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