-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refresh access token during soak test #3268
Comments
Hi @schurmann, sorry for the slow reply. Unfortunately what you propose have ... a few problems ... and actually already works. import { setInterval } from "k6/experimental/timers";
setInterval(() => {
console.log("in interval");
}, 100); This will continously print "in interval". The current event loop will not continue executing the next part of the test until all jobs are finished. This allows you to make a request for example and not start an new iteration or the test to just finish, until the response is actually returned. In this case this means that we won't continue after the init as ... we have a function that is to be exectued each 100ms. If you clear the interval after sometime the execution will continue. In theory k6 can have "special" treatment for something. But IMO this will be:
The usual proposal here is to just check that the token was generated soon enough on iteration start as explained here. Some other notes:
Seems to me like you are not understanding that each VU is a separate JS VM which willl run the init code once - so it loads it source and knows what actually to do. And then k6 will instruct it when to run the There is no actual way for you to run code that doesn't run on the VU loop as ... JS is single threaded and we want to run in the same VU.
This might be doable once we have a way to not emit metrics with certain calls - but it is not doable currently. See #1321 which to be honest should be picked up, but is unlikely to happen soon, given current priorities. |
Thanks for the detailed answer! I have decided not to pursue this further since the current K6 architecture isn't flexible enough for our needs. I might come back to K6 in the future when native histograms are no longer experimental in prometheus and there is a way to update a shared state asynchronously (e.g. the access token). Feel free to close this. |
Hey, Team! Is there any update on this topic? I will be looking for this feature soon, how to refresh token during long run test. |
Uncertain if this is solved by https://community.grafana.com/t/periodically-refreshing-a-token-aside-a-script/99736/3, but it is a result I came to; and we now have a ticket in backlog at work to solve, so would be happy to share what we come up with if it is not the grafana community forum solution. |
Hi @LewisCowlesMotive - yes this is the alternative which I apperantly didn't mention while I was explaining why having timeouts between iterations is not really compatible 🤦 But yes - you cna have code that checks (either before every request or usually at iteration beginning) if the token will expire in X amount of time and ... relogin. |
Feature Description
I need a way to refresh an access token that is used for authorization during a soak test. It is important that is token is refreshed asynchronously and outside the VU loop to not skew the metrics.
Suggested Solution (optional)
Enable
setInterval
usage in init context.Already existing or connected issues / PRs (optional)
No response
The text was updated successfully, but these errors were encountered: