I am trying to write some load tests that make an auth call and then use that same token for each call in the scenario.
I am having trouble with getting it to check if the token has been set, if not then call to get the token. Otherwise is the token is set, then execute the calls.
My code that does this check looks like this:
val scn = scenario("Get All Events")
.doIf(session => session("bearerToken").asOption[String].isEmpty) {
exec(getAuth.getBearerToken)
}
.pause(2)
.exec (http("Get Events")
.get("v1/events")
.header("x-request-id", "perf-test")
.header("HttpLogRequestId", s"${BaseHelpers.getUUID}")
.header("x-api-key", s"${BaseHelpers.getXAPIKey}")
.header("Authorization", "Bearer ${bearerToken}")
.check(status.is(200))
)
When it calls to set the auth token it looks like this:
val getBearerToken = exec(http("Get Authorization Token")
.post(baseAuthURL + "v1/oauth2/token?grant_type=password&client_id=" + client_id + "&username=" + username + "&password=" + password)
.basicAuth(client_id, client_secret)
.header("x-request-id", "perf-test")
.header("HttpLogRequestId", s"${BaseHelpers.getUUID}")
.check(status.is(200))
.check(jsonPath("$.id_token").saveAs("bearerToken"))
)
The result for me is generally one of two things. Either it will make this call each time, somehow ignoring the check or it will error out telling me the key is not found.
I have tried doing this a few different ways and still no luck. Hoping a second set of eyes might point out where I am going wrong.