# AsLongAs end scenario ?

**URL:** <https://community.gatling.io/t/aslongas-end-scenario/2324>\
**Category:** Gatling (Open-Source)\
**Created:** [May 28, 2015, 1:28pm UTC](https://community.gatling.io/t/aslongas-end-scenario/2324 "2015-05-28T13:28:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hou\_Marina](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@Hou\_Marina](https://community.gatling.io/u/Hou_Marina)\
**Post date:** [May 28, 2015, 1:28pm UTC](https://community.gatling.io/t/aslongas-end-scenario/2324/1 "2015-05-28T13:28:47Z")

</div>

Hello,

On my scenario, I used an AsLongAs method to check whether a condition is valid or not, and then, use a get request. Yet, my get request never happen…

Here is what was on my scenario :  
scenario(“XXX”).exec(http(“action”)…)  
.asLongAs( condition ) (  
exec( http(“action”).get( … ) )  
)  
.exec(  
http(“this-request-never-happened”)  
.get(" ")  
)

Am I doing it wrong ?

Thanks for your feedback.

---

<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:** [May 28, 2015, 1:48pm UTC](https://community.gatling.io/t/aslongas-end-scenario/2324/2 "2015-05-28T13:48:27Z")

</div>

You have to be more specific.  
Are you sure that your condition become invalid at some point so you exit the loop?  
Are you sure your condition is something that gets reevaluated on each iteration and not a static value?

---

<div class="post-metadata">

**Author:** ![Hou\_Marina](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@Hou\_Marina](https://community.gatling.io/u/Hou_Marina)\
**Post date:** [May 28, 2015, 2:14pm UTC](https://community.gatling.io/t/aslongas-end-scenario/2324/3 "2015-05-28T14:14:24Z")

</div>

Yes I am sure the condition become invalid at some point. I do exit the loop, the simulation ends well.

Here is my code :

.exec(  
http(“get-status”)  
.get("/action/show/${id}").asJSON  
.check(jsonPath("$…status").saveAs(“new\_status”)  
.asLongAs(session =\> session(“new\_status”).as[String] != “done” && session(“new\_status”).as[String] != “killed”) (  
exec(  
http(“follow-action”)  
.get("/action/show/${id}").asJSON  
.check(jsonPath("$…status").saveAs(“new\_status”)  
)  
.exec(  
http(“the-request-that-ever-happen”)  
.get(“action/show/${id}).asJSON  
.check(jsonPath(”$…status").is(“done”)

Thanks again for your feedback.  
Maybe there is a better way to do it…

---

<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:** [June 4, 2015, 10:14am UTC](https://community.gatling.io/t/aslongas-end-scenario/2324/4 "2015-06-04T10:14:49Z")

</div>

There’s a cleaner way to write the asLongAs condition so you don’t have to perform the request once before the loop:

session =\> session(“new\_status”).asOption[String].map(value =\> value != “done” && value != “killed”).getOrElse(true))

Then, I have no idea why you don’t get the expected behavior.

I would need you to provide a runnable sample so I can reproduce.

Cheers,
