public static void waitOrTimeout(long timeout, Runnable block) throws InterruptedException {
    long startTime = System.currentTimeMillis();
    long duration;

    while (true) {

      try {
        Thread.sleep(1000);

        block.run();
        return;
      } catch (AssertionError e) {
        duration = System.currentTimeMillis() - startTime;

        if (duration >= timeout) {
          throw e;
        }
      }
    }
  }
Re-run the given block until it no longer raises an AssertionError, or it times out.

@param timeout timeout in ms
@param block block to run
end-to-end-tests/src/main/java/com/amazonaws/blox/integ/AsynchronousTestSupport.java