-1

At the beginning of my K6 test, I use my setup() function to ask for a token with the objective of use it on every VU. I don't want each VU using its own token, I want the same for every VU. That's OK, I can do it, but the problem comes when I need to refresh this token after 1 hour of test.

Again, I want to get a new token and use the same new token to every VU (I don't want that every VU get a new different token, I want the same for every VU). I am not able to do it with K6.

How can I face it? Is there a way for sharing variables between VUs? If not, which is the best way of doing it?

Thanks a lot.

I tried to start a new scenario after 1 hour that update the variable, but the VUs that are already running doesn't get that change.

1 Answers1

1

As each k6 VU operates within its own JavaScript runtime, there is no way for them to communicate with each other without some kind of intermediary.

The easiest way to allow your VUs to talk to each other is to use the experimental Redis module. Of course, that means running a Redis server, but that's fairly trivial to set up.

Example usage can be found here.

So for your specific case, you would probably want to have two scenarios:

In one scenario, you run a single VU that handles retrieval of tokens on some interval (you should be able to retrieve a refresh token at will by calling the relevant endpoint, so you can choose the frequency). This VU sets a key=value pair on Redis with await redisClient.set('token', "<token value>");.

The VUs in the second scenario would call await redisClient.get('token'); which will block execution until the given key becomes available. You may want to implement some logic to only retrieve a new token when you detect that it needs refreshing.

Tom
  • 126
  • 1