Skip to content

Commit de73397

Browse files
authored
Add configurable timeout safe await method (#117296)
Add a method for a configurable timeout with countdown latches.
1 parent bead248 commit de73397

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
@@ -2331,10 +2331,18 @@ public static void safeAwait(CyclicBarrier barrier) {
23312331
* flag and asserting that the latch is indeed completed before the timeout.
23322332
*/
23332333
public static void safeAwait(CountDownLatch countDownLatch) {
2334+
safeAwait(countDownLatch, SAFE_AWAIT_TIMEOUT);
2335+
}
2336+
2337+
/**
2338+
* Await on the given {@link CountDownLatch} with a supplied timeout, preserving the thread's interrupt status
2339+
* flag and asserting that the latch is indeed completed before the timeout.
2340+
*/
2341+
public static void safeAwait(CountDownLatch countDownLatch, TimeValue timeout) {
23342342
try {
23352343
assertTrue(
23362344
"safeAwait: CountDownLatch did not reach zero within the timeout",
2337-
countDownLatch.await(SAFE_AWAIT_TIMEOUT.millis(), TimeUnit.MILLISECONDS)
2345+
countDownLatch.await(timeout.millis(), TimeUnit.MILLISECONDS)
23382346
);
23392347
} catch (InterruptedException e) {
23402348
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)