Skip to content

Instantly share code, notes, and snippets.

@eeichinger
Last active August 12, 2016 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eeichinger/f479ac067bd02d0c608a645c77398823 to your computer and use it in GitHub Desktop.
Save eeichinger/f479ac067bd02d0c608a645c77398823 to your computer and use it in GitHub Desktop.
in asychronous test cases it sometimes is necessary to wait for a condition to occur
@SneakyThrows
private static <T> void assertThatWithSpinWait(Callable<T> actual, Matcher<? super T> matcher, long timeoutMillis) {
long endMillis = System.currentTimeMillis() + timeoutMillis;
while (System.currentTimeMillis() < endMillis) {
try {
assertThat("", actual.call(), matcher);
return;
} catch (AssertionError ignored) {
// ignore
}
}
assertThat("", actual.call(), matcher);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment