-
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
How I share auth cookie with the rest of tasks only for current locust user? #733
Comments
you never created an instance of |
@cgoldberg i did try although i am getting the same results, Would you be able to share an example! |
Your code doesn't define a class correctly. It's a plain old Python class... so it needs an So maybe:
You will first need to instantiate the |
@cgoldberg I have tried you suggestion and, the result is same, as in s.cookie is the same for all locust users. It seems that storage is initialized on locust start and not on each user/client/thread. I have created a dummy locust script to make it easier to see the results:
|
You are creating an instance at the module level, so it is shared. You need to create it inside your Locust class, so an instance is created for each user. https://docs.locust.io/en/latest/writing-a-locustfile.html#the-locust-class |
I did look at the document, although i did not find a way how to share a single instance of |
@cgoldberg I've been playing around trying various approaches, and I am not getting any good results. I have simplified the approach to see if I get a new cookie per user spawned per user. I have included the code below. I have started locust with 2 users and 2 hatch rate with the execution log below. I was expecting to see:
Although what I saw was:
Something is off:
output:
|
you still aren't creating the storage instance in your Locust class (the classes based on HttpLocust). as for your other questions/issues, I really have no idea what you are trying to do... and this entire thread is getting confusing. I'm closing it, since there is no Locust issue. |
I will review my approach, and if needed create another ticket with details specifically to the issue as you have mentioned that this thread is getting confusing. |
Why have separate classes at all? If you encapsulate the whole flow for each user on a single class then you can store the cookies on objects of that type. This worked for me: https://gist.github.com/MatrixManAtYrService/1d83abd54adc9d4181f9ebb98b9799f7 |
@alexanderdevm, I want to generate the token at load generation time means I want to use the same token for all locust instances.But If I follow your code, it is not working. Still it is generating the different token for every locust instance. Please can any one help me on this |
Calling the class instance variable directly worked for me without instantiating the Storage class Here is an example of how I setup things on my end auth.py
locustfile.pyEnsure to make the proper imports
NOTE > So now each time you need to refer to the token just do some thing like @events.init.add_listener ==> https://docs.locust.io/en/stable/writing-a-locustfile.html#init |
I am looking into to moving my multi-threaded python script to locust.
A simple explanation of what my script does is:
Create a thread per user
In each thread authenticates user and get auth cookie
With that auth cookie perform various api calls at a set interval
When i started looking into locust, I have noticed that the only way to perform each task at its own specific interval, I would need to create a taskset per task.
This brought up an issue of how do i share the auth cookie for the given spawned user between task sets? Since in the long run I also need to share response data between taskset for the given spawned user as it differs between spawned users.
In the sample code below, all of the users spawned by locust, share the same "storage.cookie". Is there a way to keep storage.cookie unique per user, share it with all tasks sets for the given spawned user by locust ? Does locust report on which user is currently executing the task?
Stack overflow copy: https://stackoverflow.com/questions/48739300/locust-how-i-share-auth-cookie-with-the-rest-of-tasks-only-for-current-locust-u
The text was updated successfully, but these errors were encountered: