Periodically refreshing a token aside a script

Hi everyone,

I’ve the following issue : I’m currently scripting a user journey. The authentication needs to be refreshed every 5 seconds while I’m running my test.

In other load testing tools I would have use a while loop inside a fork but here, I don’t even see a correct solution.

has anyone already faced this problem ? How did you solved it ?

Thanks in advance !

Hi @camillegr,
welcome to the community forum :tada:

If you can use a dedicated token per VU then you can check the time elapsed from the last refresh and execute a new one after 5 seconds.

var refreshed = 0;

export default function() {
	var diff = new Date() - refreshed 
	if (diff > 4999) {
		console.log(`refresh the token`)
		refreshed = new Date()

Even better if you create an HTTP wrapper where this logic is executed before each request so the code will be cleaner.

When the PR for #882 will be merged then a setTimeout could be a valid alternative. You can subscribe to it to know when it will be available.

Hi @codebien,

I think the http wrapper is a good solution. I’ll take a look at it.

thanks for your answer !