Hi @nathanloyer
A warm welcome to the community forum
It is usually very useful to provide an example in order to help you out.
From what I understand, what you can easily do is have the VUs use a token, and update the token for each VU. For example:
// init import modules
import { sleep } from 'k6'
import exec from 'k6/execution';
// init context: define k6 options
export const options = {
vus: 3,
duration: '4s',
};
// init context: global variables
let vuTokens = ['initial-token-user-1', 'initial-token-user-2', 'initial-token-user-3']
let myToken;
export default function () {
// init token if not defined yet
if (!myToken) myToken = vuTokens[__VU - 1];
// update token at iteration 2
if (exec.vu.iterationInInstance === 2) myToken = `new-token-user-${__VU}`;
// log VU, iteration, token
console.log(`[VU: ${__VU}, iteration: ${__ITER}, token: ${myToken} `);
sleep(1);
}
Would assign a different token at the first iteration. In your case, once it expires, you’d have to request a new token.
INFO[0000] [VU: 1, iteration: 0, token: initial-token-user-1 source=console
INFO[0000] [VU: 2, iteration: 0, token: initial-token-user-2 source=console
INFO[0000] [VU: 3, iteration: 0, token: initial-token-user-3 source=console
INFO[0001] [VU: 3, iteration: 1, token: initial-token-user-3 source=console
INFO[0001] [VU: 2, iteration: 1, token: initial-token-user-2 source=console
INFO[0001] [VU: 1, iteration: 1, token: initial-token-user-1 source=console
INFO[0002] [VU: 3, iteration: 2, token: new-token-user-3 source=console
INFO[0002] [VU: 1, iteration: 2, token: new-token-user-1 source=console
INFO[0002] [VU: 2, iteration: 2, token: new-token-user-2 source=console
INFO[0003] [VU: 1, iteration: 3, token: new-token-user-1 source=console
INFO[0003] [VU: 3, iteration: 3, token: new-token-user-3 source=console
INFO[0003] [VU: 2, iteration: 3, token: new-token-user-2 source=console
We have SharedArray that the VUs can access, but not update. That is, we cannot have is a variable shared between different VUs that the VU code can update.
Would something like the above work for your case, having the VU get their own token when it expires? If you declare the variable in the init
section, the VU code should be able to update and reuse it between expirations.
I hope this helps!