diff --git a/testing/trino-testing-services/src/main/java/io/trino/testing/assertions/Assert.java b/testing/trino-testing-services/src/main/java/io/trino/testing/assertions/Assert.java index 35205085c25c..42cf8c347ce3 100644 --- a/testing/trino-testing-services/src/main/java/io/trino/testing/assertions/Assert.java +++ b/testing/trino-testing-services/src/main/java/io/trino/testing/assertions/Assert.java @@ -58,6 +58,27 @@ public static void assertEventually(Duration timeout, Dura } } + public static void assertConsistently(Duration timeout, Duration retryFrequency, Assert.CheckedRunnable assertion) + throws E + { + long start = System.nanoTime(); + while (!Thread.currentThread().isInterrupted()) { + assertion.run(); + + if (Duration.nanosSince(start).compareTo(timeout) > 0) { + return; + } + + try { + Thread.sleep(retryFrequency.toMillis()); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } + } + } + public interface CheckedRunnable { void run()