Skip to content

Commit 0559d6a

Browse files
authored
Add configurable timeout safe await method (#117296) (#117300)
Add a method for a configurable timeout with countdown latches.
1 parent 45d5990 commit 0559d6a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2301,10 +2301,18 @@ public static void safeAwait(CyclicBarrier barrier) {
23012301
* flag and asserting that the latch is indeed completed before the timeout.
23022302
*/
23032303
public static void safeAwait(CountDownLatch countDownLatch) {
2304+
safeAwait(countDownLatch, SAFE_AWAIT_TIMEOUT);
2305+
}
2306+
2307+
/**
2308+
* Await on the given {@link CountDownLatch} with a supplied timeout, preserving the thread's interrupt status
2309+
* flag and asserting that the latch is indeed completed before the timeout.
2310+
*/
2311+
public static void safeAwait(CountDownLatch countDownLatch, TimeValue timeout) {
23042312
try {
23052313
assertTrue(
23062314
"safeAwait: CountDownLatch did not reach zero within the timeout",
2307-
countDownLatch.await(SAFE_AWAIT_TIMEOUT.millis(), TimeUnit.MILLISECONDS)
2315+
countDownLatch.await(timeout.millis(), TimeUnit.MILLISECONDS)
23082316
);
23092317
} catch (InterruptedException e) {
23102318
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)