Hi,
I would like to get some suggestions on how to exit a block of requests only when a certain type of failures happen.
For example, I have a scenario of 5 requests:
val scn = scenario(“scenario”).exec(request 1).exec(request 2).exec(request 3).exec(request 4).exec(request 5)
Let request 2,3,4 be a block. I would like to exit block if and only if
- Any request in the block return 403 status code
- Request 3 fails
exitHereIfFailed cannot be used because request 5 should always be executed.
exitBlockOnFailed cannot be used because on certain failures the execution should continue (e.g. request 2 returns 500 status code)
So far the only solution I have is to have a doIf around each request in the block:
exec(request 1)
.exec(request 2)
.doIf(status code is not 403) {
exec(request 3)
.doIf(status is ‘OK’) {
exec(request 4)
}
}
.exec(request 5)
Does Gatling or Scala provide something like a GOTO statement? Or is it possible to implement an exitBlockOnFailedWithCondition?
Any suggestion/comment is appreciated.
Brian
Hi Brian,
Try to think about it the other way around. You can use exitBlockOnFail with a twist, filtering out bad requests one a time, and adding a check on the last request to make sure it didn’t fail, either on status or content.
Something like this:
exec(http("request1")...)
.exec(http("request2")...)
.exitBlockOnFail {
exec(
http("request3")...
.check(status.not(403))) // "not" is what you wan't
.exec(
http("request4")...
.check(status.not(403)))
.exec(
http("request5")...
.check([status.is](http://status.is)(200))) // or any check on content
}
Cheers,
Guillaume.
Obviously, request2 should be inside the block with a check(status.not(403)) and request5 outside the block without any particular check!
Guillaume.
Hi Guillaume thanks for the reply
However, I still want to see KOs in the report for other non 200s status code. For example, if my request 4 returns a 500, a check(status.not(403)) will consider my request as a OK, which it will not show in the report.
Sorry I wasn’t clear on that in the original post, but that is quite important to me. 200 => OK and continue, 403 => KO and exit block, other status code => KO and continue.
Brian
I think I can probably solve my issue using asLongAs loop with exitASAP=true. The condition is checked after each call within the loop.