# Exit scenario on condition or after 12 repeats

**URL:** <https://community.gatling.io/t/exit-scenario-on-condition-or-after-12-repeats/3104>\
**Category:** Gatling (Open-Source)\
**Created:** [June 24, 2016, 6:50pm UTC](https://community.gatling.io/t/exit-scenario-on-condition-or-after-12-repeats/3104 "2016-06-24T18:50:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alitsiya.yusupova](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@alitsiya.yusupova](https://community.gatling.io/u/alitsiya.yusupova)\
**Post date:** [June 24, 2016, 6:50pm UTC](https://community.gatling.io/t/exit-scenario-on-condition-or-after-12-repeats/3104/1 "2016-06-24T18:50:46Z")

</div>

Hi,

I have a get request which after about 60 seconds (it can take less or more) should return “complete” status. If this didn’t happen after 2 min, this means that test is failed. The code below doesn’t exit after “final status check”:

`

```auto
.asLongAs(_("status").as[String] != "complete"){
   repeat(12){
     pause(10)
    .exec(http("status check")
        .get("/api/v2/applications/" + _("param").as[String])
        .header("Content-Type", "application/json")
        .queryParam("api_key", Settings.api).asJSON
          .check(jsonPath("$.download.status").saveAs("status"))
    )
   }
   .exec(http("final status check")
      .get("/api/v2/applications/" + _("param").as[String])
        .header("Content-Type", "application/json")
        .queryParam("api_key", Settings.api).asJSON
        .check(jsonPath("$.download.status").is("complete"))
      )
      .exitHereIfFailed
}

```

`

If I would simply do retries, this will add “KO” to test summary every 10 seconds. Since status “complete” is expected somewhere between 1 and 2 minutes, I want the scenario to be “fail fast”.

Is there a way to modify the code above to exit on fail after 12 retries or earlier if condition “asLongAs” is met.

Thank you!

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [July 8, 2016, 6:28am UTC](https://community.gatling.io/t/exit-scenario-on-condition-or-after-12-repeats/3104/2 "2016-07-08T06:28:55Z")

</div>

[http://gatling.io/docs/2.2.2/general/scenario.html?highlight=trymax#trymax](http://gatling.io/docs/2.2.2/general/scenario.html?highlight=trymax#trymax)
