0

I have this request that is querying my service which is inside of tryMax.

The access token to authenticate a request expires every five minutes and is generated at the beginning of the simulation run as ${token}

Is there a way within the tryMax to send another token generation request that will update the expired ${token} (Authorization header value) if the response code is 401 or the response body contains information about the request not being authenticated. Then retry the request before tryMax moves to the next iteration?

I have tried setting status code as a session attribute, however the request is not being sent and the token doesn't update, I tried doing a .doIf after the request exec, putting a doIf inside it's own exec and even playing around with transformResponse, all with no success.

Any suggestions how to approach this?

Przemek Hendel
  • 60
  • 1
  • 10

1 Answers1

0

you can do something like what is outlined in Gatling (performance test):how to perform task in background every x-minutes

However - is this really the scenario you want to model? How does the client you are simulating handle the 401? The scenario you are proposing only works if the client is in charge of manually handling its own refreshes.

James Warr
  • 2,552
  • 2
  • 7
  • 20
  • the issue was a little more complex than I though but I somehow managed to solve it. I missed out that when no `status` check is present there still is one that is being done that checks for `200` or `304` I managed to handle the authorization that I send a silent request which only saves the request status code, then I proceed to `.doIf(session => session("status").as[Int] == 401 || (session("tokenGenerationTime").as[Long] - System.currentTimeMillis()) > 180000L) ` if the expression istrue it generates the new token and proceeds to the second `doIf` after this one which sends the request – Przemek Hendel Jun 08 '19 at 08:21