# How to fail on doWhileDuring timeout?

**URL:** <https://community.gatling.io/t/how-to-fail-on-dowhileduring-timeout/6687>\
**Category:** Gatling (Open-Source)\
**Created:** [April 20, 2022, 5:13am UTC](https://community.gatling.io/t/how-to-fail-on-dowhileduring-timeout/6687 "2022-04-20T05:13:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![agattik](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@agattik](https://community.gatling.io/u/agattik)\
**Post date:** [April 20, 2022, 5:13am UTC](https://community.gatling.io/t/how-to-fail-on-dowhileduring-timeout/6687/1 "2022-04-20T05:13:00Z")

</div>

Hello!

I need to poll a URL repeatedly until it returns a value, or a timeout occurs. I want to fail in case of timeout. The following Java code works, but the simulation succeeds (rather than failing) on the `exitHereIf`. The DSL doesn’t offer a `check()` at that point.

```auto
exec(session -> session.set("status", -1))
                .group("Wait for agreement")
                .on(doWhileDuring(session -> session.getString(CONTRACT_AGREEMENT_ID) == null, Duration.ofSeconds(30))
                        .on(exec(getContractStatus()).pace(Duration.ofSeconds(1)))
                )
                .exitHereIf(session -> session.getString(CONTRACT_AGREEMENT_ID) == null)

```

---

<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:** [April 20, 2022, 5:33am UTC](https://community.gatling.io/t/how-to-fail-on-dowhileduring-timeout/6687/2 "2022-04-20T05:33:45Z")

</div>

What do you mean by “succeed” and “fail”?  
Have you checked [assertions](https://gatling.io/docs/gatling/reference/current/core/assertions/)?

---

<div class="post-metadata">

**Author:** ![agattik](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@agattik](https://community.gatling.io/u/agattik)\
**Post date:** [April 20, 2022, 5:37am UTC](https://community.gatling.io/t/how-to-fail-on-dowhileduring-timeout/6687/3 "2022-04-20T05:37:58Z")

</div>

I mean to stop the scenario execution. E.g. ten virtual users each run HTTP request to initiate a contract agreement, then poll until the contract agreement is obtained, then do further steps. If the poll stops for one virtual user, I don’t want to run the further steps for that user, and ideally I wouldn’t stop the simulation for other virtual users immediately.

---

<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:** [April 20, 2022, 6:40am UTC](https://community.gatling.io/t/how-to-fail-on-dowhileduring-timeout/6687/4 "2022-04-20T06:40:47Z")

</div>

> I don’t want to run the further steps for that user,

What you’ve done should work. If it doesn’t, it means your `session.getString(CONTRACT_AGREEMENT_ID) == null` condition doesn’t work.

> ideally I wouldn’t stop the simulation for other virtual users immediately

The only way to do that is to trigger a `System.exit()` but this won’t generate the reports.
