Hi All, I am new to Gatling and scala. I am trying to execute a scenario for 2 hours and after 1 hour I am getting a 401 as my token goes expired.
Is it a way to check the token is active or is there any way forward? appreciated your help for this.
thanks
Mikhail
November 7, 2020, 8:29am
#2
Hi,
You can do the following:
Add check to the response which returns 401 eventually, something like this:
.check(status.saveAs(“lastResponseStatus”)
.doIf(session => session(“lastResponseStatus”).as[Int] == 401)
{
// authenticate again
}
Thank you for the reply. I did manage to create the function. But I want to execute the authentication method once in 1 hour when my scenario is executing say 5 hours. I dont want to kill my token server [which is shared with plenty of apps]. Can I execute the method authenticate only once. My method is like this…
Thanks in Advance!!
Hello, have you managed to resolve your problem?
I have the same situation with token expiration, and need your help)
понедельник, 9 ноября 2020 г. в 23:31:30 UTC+2, diju....@gmail.com :
You could proactively refresh your token before it expires, the same way you’ve loaded it in the first place.
Yes. Sorry for the late reply. Recently I have managed to find a solution for this. We can add the token into
def setToken: Expression[Session] = session => {
val accessToken = gettoken();
session.set(“token”,setToken)
}
Once we have this, we can add this into a loop.
If also synchronize this call, it wont be kill the token generator. Hope this helps