Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable timeout safe await method #117296

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2331,10 +2331,18 @@ public static void safeAwait(CyclicBarrier barrier) {
* 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();
Expand Down