mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-22 06:07:55 -04:00
Add configurable timeout safe await method (#117296)
Add a method for a configurable timeout with countdown latches.
This commit is contained in:
parent
bead24880b
commit
de73397a05
1 changed files with 9 additions and 1 deletions
|
@ -2331,10 +2331,18 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|||
* flag and asserting that the latch is indeed completed before the timeout.
|
||||
*/
|
||||
public static void safeAwait(CountDownLatch countDownLatch) {
|
||||
safeAwait(countDownLatch, SAFE_AWAIT_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Await on the given {@link CountDownLatch} with a supplied timeout, preserving the thread's interrupt status
|
||||
* flag and asserting that the latch is indeed completed before the timeout.
|
||||
*/
|
||||
public static void safeAwait(CountDownLatch countDownLatch, TimeValue timeout) {
|
||||
try {
|
||||
assertTrue(
|
||||
"safeAwait: CountDownLatch did not reach zero within the timeout",
|
||||
countDownLatch.await(SAFE_AWAIT_TIMEOUT.millis(), TimeUnit.MILLISECONDS)
|
||||
countDownLatch.await(timeout.millis(), TimeUnit.MILLISECONDS)
|
||||
);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue