Updating session variable to exit asLongAs not working

Hi All,

I am creating a data mart and polling for its status till it is complete easily enough in JAVA but find it challenging in Gatling. Following is my code so far:

  1. val scn = scenario(scenarioName = “Materialization”)
  2. // .exec(session => {session.set(“status”, “”); session})
  3. .exec(http(requestName = “Initiate”)
  4. .post(baseurl+"/materialize/datamart/initiate")
  5. .headers()
  6. .body(StringBody("""{"…}"""))
  7. .basicAuth("","")
  8. .check(jsonPath("$.martRequestId").saveAs(“martID”)))
  9. .asLongAs(session => session(“status”).asOption[String] != “CMPLT”) {
  10. (exec(http(requestName = “Wait for completion of materialization”)
  11. .post(baseurl + “/services/statuses”)
  12. .headers(headers_API_Diver_G)
  13. .body(StringBody("""{“martRequestIds”: ["${martID}"],“bulkRequestIds”: []}"""))
  14. .basicAuth("", “”)
  15. .check(jsonPath("$.martRequestStatuses[*].statusCode").saveAs(“status”)))
  16. .exec(session=> {
  17. println(“Status:” + session(“status”).as[String])
  18. val newSession = session.set(“status”,"${status}")
  19. newSession
  20. })
  21. .pause(10))
  22. }

The outputs I get from the println in the last exec block are all the status transitions, including CMPLT. This means that the session variable has been updated successfully but the loop still does not terminate, because the session condition is not satisfied somehow.

Kindly advise on how I can fix this.

Thanks,
Hasan

https://gatling.io/docs/current/session/session_api/#setting-attributes

Session instances are immutable!

Adding exitASAP did the trick!

.exec(session=> {
  val newSession = session.set("status","")
  newSession
})
.asLongAs(condition=session => session("status").as[String] != "CMPLT", exitASAP=true) {

exitASAP should not be marked optional, should it?