wait for a fixed amount of time without until-condition

5,885 views
Skip to first unread message

Manuel Mauky

unread,
Dec 12, 2017, 10:51:22 AM12/12/17
to Awaitility
Hi,

is it possible to let awaitility to wait for a fixed amount of time without a condition?

Basically I'd like to say "wait for x seconds". I'm new to the API but as far as I can see with the methods on the ConditionFactory we only configure
logic for how long it will wait but the actual "waiting" is started with "until". However, I don't know what to provide to the until method.

I tried something like this:

await().atMost(1000, MILLISECONDS).until(() -> true);

However, this throws a ConditionTimeoutException.

Best regards, Manuel

Johan Haleby

unread,
Dec 14, 2017, 1:37:04 AM12/14/17
to await...@googlegroups.com
Hi,

I don't see a reason for why you want to use Awaitility for this, just use Thread.sleep(..)?

Regards,
/Johan

--
You received this message because you are subscribed to the Google Groups "Awaitility" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awaitility+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Golam Rabbi

unread,
Aug 31, 2019, 6:07:15 AM8/31/19
to Awaitility
Because Thread.sleep(...) is not machine-independent. 

"Using Thread.sleep in a test is just generally a bad idea. It creates brittle tests that can fail unpredictably depending on environment ("Passes on my machine!") or load. Don't rely on timing (use mocks) or use libraries such as Awaitility for asynchroneous testing."  - SonarQube


On Thursday, December 14, 2017 at 8:37:04 AM UTC+2, Johan Haleby wrote:
Hi,

I don't see a reason for why you want to use Awaitility for this, just use Thread.sleep(..)?

Regards,
/Johan
On Tue, Dec 12, 2017 at 4:51 PM, Manuel Mauky <manue...@gmail.com> wrote:
Hi,

is it possible to let awaitility to wait for a fixed amount of time without a condition?

Basically I'd like to say "wait for x seconds". I'm new to the API but as far as I can see with the methods on the ConditionFactory we only configure
logic for how long it will wait but the actual "waiting" is started with "until". However, I don't know what to provide to the until method.

I tried something like this:

await().atMost(1000, MILLISECONDS).until(() -> true);

However, this throws a ConditionTimeoutException.

Best regards, Manuel

--
You received this message because you are subscribed to the Google Groups "Awaitility" group.
To unsubscribe from this group and stop receiving emails from it, send an email to await...@googlegroups.com.

Ádám Zovits

unread,
Jun 19, 2023, 10:08:01 AM6/19/23
to Awaitility
Manuel's initial approach was almost spot-on, it just needs a minor adjustment:
Awaitility.await().pollDelay(5, TimeUnit.SECONDS).until(() -> true);
Except when you want to wait more than 10 seconds (the default timeout value), because then you have to specify a timeout larger than that:
Awaitility.await().pollDelay(15, TimeUnit.SECONDS).atMost(16, TimeUnit.SECONDS).until(() -> true);
So there is a workable solution, using a tool that was never intended to be used this way.
Reply all
Reply to author
Forward
0 new messages