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?