Use awaitility and check a value is not changed for wait time

2,115 views
Skip to first unread message

Ankit Soneji

unread,
Jun 8, 2016, 12:55:37 PM6/8/16
to Awaitility
Use awaitility and check a value is not changed for wait time


I want to wait upto 10 seconds and make sure recivedMessagesForTestId returns false the entire time. The thing is the method always return false from the beginning. So with the bellow code it checks the value for the first time and since its false first time it stops checking. In my case I want to keep checking the value and make sure it's false for given time (10 seconds).

await().with().pollInterval(3, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS).until(recivedMessagesForTestId(testId), is(false));

Johan Haleby

unread,
Jun 9, 2016, 7:01:19 AM6/9/16
to await...@googlegroups.com
Awaitility can't help you with that. It's designed to check for state transitions.

--
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+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ankit Soneji

unread,
Jun 10, 2016, 1:09:47 PM6/10/16
to Awaitility
Can this be a feature enhancement? I want to be able to make sure the state transitions does not change for given time. I don't mind trying to contribute this change if get little bit of guidance.

thanks,

ankit

Johan Haleby

unread,
Jun 12, 2016, 12:57:48 AM6/12/16
to await...@googlegroups.com
Well maybe but I suspect it's going to be quite difficult and I'm not sure if the extra complexity is worth. If I understand you correctly you'd like a DSL for describing patterns instead of a single condition. Something like this:

Pattern pattern = Pattern.between(1, SECONDS).and(2, SECONDS).assertThat(someConditionIs(false)).and().between(2, SECONDS).and(3200, MILLISECONDS).assertThat(someConditionIs(true)).then().assertThat(someConditionIs(false)).forDuration(2, SECONDS);

await().pattern(pattern);

While it would be quite cool, I'm not sure it's worth the extra complexity and the time it would take to implement something like this (I think).

Today you could probably use this workaround:

// First pattern
await().atLeast(1, SECONDS).and().atMost(2, SECOND).until(somConditionIs(false));

// Second pattern
await().atMost(1200, MILLISECONDS).until(somConditionIs(true));

// Third pattern
await().atMost(2, SECONDS).until(somConditionIs(false));

/Johan


Reply all
Reply to author
Forward
0 new messages