-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Ability to run test_start on workers. #1408
Comments
I seem to have found a workaround for this -- bypassing the logic in class MyUser(HttpUser):
def on_start(self):
global SOME_GLOBAL
if not SOME_GLOBAL:
# do the setup work |
The setup method was removed because it was running in a bit of a strange place - people ended up getting confused because it was only being run on the first user, so if you set an instance property it would only be available on the FIRST instance of the User. Sometimes it was also run before the instance was even constructed (when there was no Another way to work around it is like this: class MyUser(User):
_first_instance = True
def __init__(self, parent):
super().__init__(parent)
if MyUser._first_instance:
MyUser._first_instance = False
# do the setup work Tbh, I'm not sure what the difference between |
Also, if what you want it just to do some general one-off initialization (not in the context of a User), you can do it using the init event, which IS triggered on all locust processes:
|
We could consider adding an additional event that is triggered on the worker nodes when they start spawning users. We would have to consider if it should trigger for new worker nodes that connects while a test is running (I guess it should?). Though I'm not sure it's necessary, since there are work-arounds like the one by @Zooce above. The setup method was removed for a good reason, and I don't think it makes sense to re-add it. |
Removing the @cyberw -- I didn't realize there was an Maybe a simple documentation update is all that is needed? |
I think you are right, the documentation is not clear and doesnt indicate that the init event is very useful for other things than adding web routes. Could I bother you to write something and make a PR? |
Certainly! I'm going to use that code you showed a couple of comments ago (if that's okay with you) since I immediately understood the usage after reading it -- it's a good example of how to use the I'll have the PR up soon. |
Is there a way to access the HTTP client from a listener? I want to be able to make a few HTTP requests to the target during the The global flag setup works fine for single-node setup but that's not ideal long term if we want to scale up. To elaborate on the use-case: I'm stress testing an API and before hammering it, I request a JWT from the auth server. I can hard-code a JWT into the Locust test, but that's a bit brittle if the JWT secret or the contents ever change. |
In short, no, not from the test_start/stop events. But there is nothing stopping you from making an HTTP request ”manually”, using |
@cyberw If I use objc[9322]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. |
Interesting. Can you share the full locustfile? In a separate ticket, because your issue doesnt really relate to the original issue. |
Is your feature request related to a problem? Please describe.
I have a load test where some setup is needed, but I really only need to do it once to set some global variables, that all spawned users to use.
Previously this was done with the
HttpLocust.setup
method. Unfortunately, now there is thetest_start
functionality which only runs on the master.Describe the solution you'd like
Allow the
test_start
functionality to run on workers.Describe alternatives you've considered
I can use the
HttpUser.on_start
method, but it results in ever single user that is spawned making a request (part of the work that I have to do in the setup), and it's not ideal.The text was updated successfully, but these errors were encountered: