score:5

Accepted answer

you have to abide by gatling apis.

  1. with checks, you don't "fail" the test, but the request. if you're looking for failing the whole test, you should have a look at the assertions api and the jenkins plugin.
  2. you can only perform a check at the request site, not later. one of the very good reasons is that if you store the bodystring in the sessions like you're doing, you'll end using a lot of memory and maybe crashing (still referenced, so not garbage collectable). you have to perform your processdata in the check, typically in the transform optional step.

score:0

i implemented something using exithereiffailed that sounds like exactly what you were trying to accomplish. i normally use this after a virtual user attempts to sign in.

exithereiffailed is used this way

val scn = scenario("myawesomescenario")
.exec(http("get data from endpoint 1")
  .get(request1url)
  .check(status.is(200))
  .check(bodystring.saveas("mydata"))
  .check(processdata(session.attributes("mydata")).is(true)))
.exithereiffailed // if we weren't able to get the data, don't continue
.exec(http("send the data to endpoint 2")
  .post(request2url)
  .body(stringbody("${mydata}"))

this scenario will abort gracefully at exithereiffailed if any of the checks prior to exithereiffailed have failed.

score:1

since the edit queue is already full.

this is already resolved in the new version of gatling. release 3.4.0

they added

exithereif

exithereif("${myboolean}")
exithereif(session => true)

make the user exit the scenario from this point if the condition holds. condition parameter is an expression[boolean].

score:2

were you looking for something like

  .exec(http("getrequest")
    .get("/request/123")
    .headers(headers)
    .check(status.is(200))
    .check(jsonpath("$.request_id").is("123")))

Related Query

More Query from same tag