Hello,
I am trying to perform a check in a tryMax loop, but I need the result of the previous tries to check the http request.
In fact, the request returns a counter, which can sometimes be incomplete compared to what I am expecting.
Here is an example :
`
val TestScn = scenario(“TEST”)
// Init session attributes
.exec((session: Session) =>
session
.set(“tmpCnt”, 0)
.set(“expectedCnt”, 2))
.tryMax(5) {
exec(http(“Test request”)
.get(“my_api_url”)
.check(
jsonPath(“my_counter_path”).transform((tmpCnt, session) => tmpCnt.toInt + session(“tmpCnt”).as[Int]).saveAs(“tmpCnt”).is(session => session(“expectedCnt”).validate[Int])))
}
setUp(TestScn.inject(atOnceUsers(1))).protocols(httpConf)
`
The request can directly return 2, which is great. But it can also return 1 on first call and 1 on second call, which is acceptable for me, but can’t be checked here as the first response value is not saved.
Do you have any idea how I could perform this kind of check ?
Thanks,
Simon Gaestel
In fact, my starting issue is different.
I have several steps in my simulation that can behave as described in my previous post, i.e sending a counter through different API calls.
I had found a way to perform my check in the tryMax loops doing this :
`
.tryMax(10) {
exec(http(“Test request”)
.get(“my_api_url”)
.check(
jsonPath(“my_counter_path”).saveAs(“tmpCnt”)))
.exec(session => session.set(“resultCnt”, session(“tmpCnt”).as[String].toInt + session(“resultCnt”).as[Int]))
.exec(session => if (session(“resultCnt”).as[Int] == session(“importNumber”).as[Int]) session else Failure(“Incomplete import number”))
}
`
My problem is that once a client reaches the max failures of a tryMax, all the next tryMax will reach the max retries, even if the condition is successfull at the first request.
I thought this was due to the way I was doing the check, but trying to reproduce it with a simple test simulation and my own check from above, it worked as I’m expecting.
Do you have any idea why a client would start reaching all max tries of a tryMax, not leaving the loop even if there is no failure ?
Thanks,
Simon Gaestel