+
+ public static void assertAndRetryIfNeeded(long timeoutInSeconds, Runnable asserter) {
+ final Instant expiry = Instant.now().plusSeconds(timeoutInSeconds);
+ while (true) {
+ try {
+ asserter.run();
+ break; // we're cool, assertion passed
+ } catch (AssertionError fail) {
+ Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
+ if (Instant.now().isAfter(expiry)) {
+ throw fail;
+ } else {
+ System.out.println("retrying after: " + fail);
+ }
+ }
+ }
+ }
+
+ @DataProvider
+ public static Object[][] trueAndFalse() {
+ return new Object[][]{{true}, {false}};
+ }
+