How to share cookies between virtual users?

I’m kicking around the idea of keeping a pool of authenticated users, and then implementing a simulation as a .randomSwitch() to enable hitting all of the different functions in the necessary proportions.

In order to do this, I need to log in as user X, then save the cookie state for that user, repeat for users Y, and user Z, and so on. Then, inside the randomSwitch, I pick a user, restore the cookie, and then execute my request.

Naturally, this means I need a thread-safe map of users to cookie values. But what I’m unclear on is, what’s the right way of preserving and restoring the state of the cookie jar? And is doing so a thread-safe thing to do? Or do I need to clone the jar before I use it?

Thanks for any advice you might have for me.

Nevermind, the added complexity of the thread-safe container for the session pool is not worth the effort. I’m going to go a different route.

What’s your goal exactly? Why not let users perform authentication?

I’ve been having this problem recently, Here’s the thing, In my test scenario I needed 10 virtual users to concurrency, but only one account password was actually provided to the virtual user to concurrency, and in the back end it seemed like the login was exchanging authorization cookies, if there is a duplicate account login will cause the previous login authorization loss(Like a refresh mechanism). So during the test, a previously logged-in virtual user will suddenly redirect back to the login page during execution.

So my first thought was to log in only once in exchange for cookies and share all the virtual users to test.

Can this be done?

And welcome to provide some new ideas.

IMO, multiple concurrent Users but only 1 actual account/password is not realistic.
But you can try .andThen to execute one single log-in to exchange for cookies , after that you can execute other scenario normally, see here

1 Like

After thinking about it, I think it’s not realistic too, I’m thinking of a new solution,but still thank you for your reply and advice.

1 Like