Skip to an exec upon check failure

I have a series of execs and one them in the middle is failing due to a check() that fails. Is there a way to skip to a later exec if that happens? Right now it just stops at that point and doesn’t call the rest of the execs in the chain.

You can wrap the call with a doIf where you would check if the previous saveAs was successful. Have a look at Gatling EL exists().

Thanks for the tip. Here is a snippet of the code. I’m trying doIfOrElse. What I’m seeing is that the else block does execute (println(“Request App Generation failed”)), but the last exec where it tries to delete the app fails because app_id is not found. Is there a reason why this variable is now gone? Do I lose session variables if a check fails? It is set in an earlier exec before the ones I pasted.

`

//… more execs above
// User clicks on the download code button

.pause(4)

.exec(http(“Request App Generation”)

.post("/generation/${app_id}")

.check(status.is(202))

.check(jsonPath("$.job_id").exists.saveAs(“job_id”)))

.pause(1)

.doIfOrElse(session => session(“job_id”).asOption[String].isDefined) {

// UI is periodically polling the generation status of the app

// We decide to enforce a timeout here whereby the user experience would be deemed poor

exec(_.set(“generation_start”, System.currentTimeMillis()))

.asLongAs(session => {

val status200 = session(“app_generation_status”).as[Int] != 200

val nonEmptyZip = session(“zip_length”).as[Int] > 0

val timedout = session(“attempts”).as[Int] > credentialsAttempts

// as long as we haven’t gotten our non-empty success, keeping trying until timeout

(!status200 || !nonEmptyZip) && !timedout

}) {

exec(http(“Fetch Generated App (Until Completed)”)

.get("/generation/${app_id}/resource/${job_id}")

.check(status.saveAs(“app_generation_status”))

.check(bodyBytes.transform(_.length).saveAs(“zip_length”))

// if we’ve reached the timeout limit, we must check if the status is 200 or fail this response

.check(checkIf((r: Response, session: Session) => session(“attempts”).as[Int] == generationAttempts) {

status.is(200)

})

.check(checkIf((r: Response, session: Session) => session(“attempts”).as[Int] == generationAttempts) {

bodyBytes.transform(_.length).not(0)

})

)

.pause(1)

.exec(session => session.set(“attempts”, session(“attempts”).as[Int] + 1))

}

.exec { session =>

val start = session(“generation_start”).as[Long]

val diff = System.currentTimeMillis() - start

println("------ " + starterName + " ------")

println(diff)

println(diff / 1000.0)

println("----------------------------------")

session

}

} {

exec { session =>

println(“Request App Generation failed”)

session

}

}

// User deletes the app (here more for cleaning/completness purposes)

.exec(http(“Delete App”)

.delete("/apps/${app_id}")

.queryParam(“delete_associated_resources”, “true”)

.queryParam(“deleteAssociatedResources”, “true”) // workaround for old bug still in staging

.check(status.is(200))

.check(jsonPath("$").saveAs(“result”)))

.exec { session =>

println(session(“result”).as[String])

session

}

`

It’s not possible that an attribute disappears. Check that it was properly set/captured in the first place.

Yes I did confirm because everything up to the doIfOrElse relies on that attribute. It’s only after the check fails that the attribute is not found.

Please provide a standalone reproducer against a public website.