Restart loop on fail

I have code that looks like this:

scenario("Test Service") .exec( SessionVariables.initialize ) .during( Test.duration ) { feed( User.feed.random ) .exec( RTDE.Login.sequence ) **.exitHereIfFailed** .exec( RTDE.SomeService.GET .request .check( jsonPath( "$" ).saveAs( RESPONSE_BODY ) ) ) }

I did that (.exitHereIfFailed) because if the login fails, there is no point in going on. But I don’t want the whole scenario to end, I just want to skip the rest of the loop body. Like this:

during( time ) {
if ( ! failed ) {
continue the test
} else {
log the user information that failed, for investigation
reset the fail flag so we can continue the loop


How to do that does not appear to be documented (that I can find). So, digging in the code, it looks like I would do it like this:

.during( Test.duration ) {
feed( User.feed.random )
.exec( RTDE.Login.sequence )
.doIfOrElse( session => session.status == OK ) {
// …
} {
// log failure
.exec( session => session.markAsSucceeded )


Seems to work. But is that the way it is meant to be done, or is there an easier way that I did not come across yet?

Why don’t you use trymax?

That doesn’t quite do what I need.

If I use tryMax, then if ANYTHING fails, it bails.

I only want to bypass the rest of the loop body if the login fails. Once past the login, failures are real failures, and I want to know about them. And the contents of that body may or may not be a linear flow where each step depends on the one before it. I may have 5 things I want to do in the body of that loop, and if they are independent, then I don’t want an error in one to stop the rest from executing.

I admit, I’m thinking like a functional tester, not a load tester. But that’s because I’m functionally testing my Gatling code. But the point is just to understand which DSL best applies to my intended scenario behavior.

You’re right?
So yes, there’s no other solution than what you’re doing ATM.

Good. Means I understand Gatling better now than I did. :slight_smile: