Is it possible to immediatly exit an entire Simulation if a check fails?

I am testing stateless web services, and my goal is to have a “capacity” test that slowly ramps requests per second until the check for exec fails.
When the check fails, it would be ideal to have the simulation finish (no reason to continue to ramp up on the failed server).
Is that possible with Gatling?

I have a script that performs the needed simulation but lacks the short circuit if the check fails

val baseURL = System.getProperty(“baseURL”, “http://localhost:9091”)
val httpProtocol: HttpProtocolBuilder = http.baseURL(baseURL)
val requestHeaders = Map(
// additional headers
“Content-Type” → “application/json”
)
val scn = scenario(“Capacity Test for Service X”)
.exec(http(“POST to sync endpoint”)
.post("/v2.0/me/sync")
.body(ELFileBody(“Capacity.json”))
.headers(boilerplate)
.headers(requestHeaders)
.check(status.is(200), jsonPath("$…syncId").exists, responseTimeInMillis.lessThan(100))
)
setUp(scn.inject(
// TODO why does only during(1800) work and not during(60 seconds)
rampRate(1 usersPerSec) to (500 usersPerSec) during (1800)
)).protocols(httpProtocol)

I tried using exitHereIfFailed but as far as I can tell, that just exits the session, it does not exit the entire simulation, but I may be wrong about that. I tried it and it did not seem to have an effect

.exec(http(“POST to sync endpoint”)
.post("/v2.0/me/sync")
.body(ELFileBody(“Capacity.json”))
.headers(boilerplate)
.headers(requestHeaders)
.check(status.is(200), jsonPath("$…syncId").exists, responseTimeInMillis.lessThan(100))
).exitHereIfFailed

Something else I noticed is that if I use latencyInMillis.lessThan(100) in the check , it never fails that check. even if I do something like latencyInMillis.lessThan(1) when I know the latencies are in the 10’s of milliseconds.

Hope I’ve explained myself we’ll, and I’m not missing something obvious (I’m by no means a Scala expert)

I am testing stateless web services, and my goal is to have a "capacity"
test that slowly ramps requests per second until the check for exec fails.
When the check fails, it would be ideal to have the simulation finish (no
reason to continue to ramp up on the failed server).
Is that possible with Gatling?

There's already a feature request for what you ask:

It will only be implemented in 2.1.

The best I could come up with for now is to stop hammering the system, but
that wouldn't stop the simulation (it will still run all your planned
virtual users, even if they do nothing). Would that suffice for now?

Something else I noticed is that if I use latencyInMillis.lessThan(100)in the check , it never fails that check. even if I do something like
latencyInMillis.lessThan(1) when I know the latencies are in the 10's of
milliseconds.

Looks like a bug.

latency check bug fixed.

Thanks for reporting!

Thanks Stéphane (sorry I didn’t spot the issue prior to posting). Also thank you on the latency fix.
" for now is to stop hammering the system" is certainly a great intermediate step prior to having the feature, but do you have any guidance on how that would look implementation wise?

Again, thanks for the help, your contributions here are quite amazing!

The idea is to store the presence of an error into a shared AtomicBoolean.

val continue = new AtomicBoolean(true)

doIf(session => continue.get) {
exec(http(“POST to sync endpoint”)
.post("/v2.0/me/sync")
.body(ELFileBody(“Capacity.json”))
.headers(boilerplate)
.headers(requestHeaders)
.check(status.is(200), jsonPath("$…syncId").exists, responseTimeInMillis.lessThan(100))
)

.exec(session =>
if (session.isFailed)
continue.set(false)
session
}
}

Get it?

thanks, this makes sense.

In case it might help others who need the same functionality, here is the working solution:

class GoogleGroupExample extends Simulation {

// Values for test run
val baseURL = System.getProperty(“baseURL”, “http://localhost:9091”)

val httpProtocol: HttpProtocolBuilder = http.baseURL(baseURL)

val requestHeaders = Map(
// additional headers
“Content-Type” → “application/json”
)

val continue = new AtomicBoolean(true)

val scn = scenario(“Capacity Test for Service X”).exec(
doIf(session => continue.get) {
exec(http(“POST to sync endpoint”)
.post("/v2.0/me/sync")
.body(ELFileBody(“Capacity.json”))
.headers(boilerplate)
.headers(requestHeaders)
.check(status.is(200), jsonPath("$…syncId").exists,
responseTimeInMillis.lessThan(150))
)
.exec((session: io.gatling.core.session.Session) => {
if (session.status == KO) {
continue.set(false)
}
session
})
})

setUp(scn.inject(
rampRate(1 usersPerSec) to (500 usersPerSec) during (60)
)).protocols(httpProtocol)
}

Followup question for this scenario:

Is it possible to get access to the Requests Per Sec metric when the check failed. Something as simple as:

println("Check failed at " + failureRequestsPerSec)

I’m currently running this test with the maven plugin via the Jenkins plugin. If the request per second at check failure were output, it could be captured by Jenkins and included in the email Jenkins sends out.

thanks again for your help

No, there’s no current access to the live stats.