How to share a variable (typically the user token) between all the iterations of the same VU?


Let’s say I have 10 VU and 5 iterations per VU, how can I share a variable between all the iterations of the same VU ?

The typical use case is to generate the token of each VU on the first iteration (each VU has a différent username). The token will then be stored in a variable that will be read in the following iterations in order to avoid having to generate the token in each iteration.

So it would look like this:

export default function(data) {
  var token = getTokenForUser(vu.idInInstance); // I would like to do this only on the first iteration of the VU and not on each iteration

I cannot do it in the setup() method as the token would be the same for all VUs (I want a différent token for each VU).

What I can think is you can generate an array of tokens in setup method tokens= [token1,token2…] And pass that value in default method. And then in default you can get tokens[ -1] and call the next method. This way vu 1 will get the zeroth token vu2 will get the first token and so on…