Re-using authentication token in multiple threads

Here’s my situation:
App I’m testing contains several more or less independent components, and one of them is an authentication system.
On one hand, I’d like something like 100 concurrent threads performing some actions on app, imitating logged in users actions, to have a decent load.
On another hand, I’m not allowed to create more than like 50 user sessions on this authentication system.

Number of concurrent user sessions is not really important for what I’m testing. Reusing user sessions will put some limitations, but is ok in general in my case.
It could be even a single user session.

Is there a proper way of doing something like following:

  1. Login is performed once (it is 1 or 2 http requests depending on situation).
  2. When token is received, it is saved and accessible to all threads.
  3. After this, load test workflow itself starts, with all threads using the same login token.
    Or it is a totally bad idea?

I’ve got some concerns with this workflow, e.g. how to re-login in case of some errors that break user session (and it can happen in my case) etc. But it could be useful for some specific tasks.

Did anyone do something similar?

1 Like

Hi, I have tried something similar for REST API where I am saving the token is accessing it for rest of the API calls.
You can save the token and access is throughout the threads.
It is very much doable.

Hi,

you can use ConcurrentHashMap for storing data accessible for all virtual users.

For example:

`

// define some types
case class MySession(id: String, username: String)
type MySessionBag = ConcurrentHashMap[String, MySession]

// create bag instance only once
val mySessionBag = new MySessionBag()

// adding to bag
mySessionBag.put(“unique_key_here”, MySession(“id_here”, “username_here”))

// getting from bag
mySessionBag.get(“key_to_look_for”)

// checking if exists in bag
mySessionBag.containsKey(“key_to_look_for”)

`

Cheers,
Adam

Thanks for replies!