How to call token generation every 5 min during stress test

I need to do a endurance test by a GET call to and endpoint for 8 hours. But the authentication token I generate expires every 5 minutes. So I need to regenerate it every 5 mins and keep on calling the same endpoint for 8 hours.
Could you help me on how to get this done in K6?

Hi @ushanib

I’m gonna give you a high level logic on how this could be implemented.

You can add a check on the response of that api call, and if the response is not 2xx (for successful, I believe that’s what you expect) you can perform a new call to refresh the token (your api must have an endpoint that is intended to be used for this purpose).

If you can sort this out, try posting your script here maybe we can help you.

Hi @ushanib ,

Another way to solve this is verify the time elapsed using de actual time and the variable exec.scenario.startTime from meta data (k6/execution) , verify this in the INIT section of your test and if it is yes, then call the regenerate token.

Hope it helps.