Last active
August 12, 2016 17:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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