Skip to content

Commit 5d5ab5b

Browse files
authored
Use safeAwait in ListenableFutureTests (#94767)
Relates #94521
1 parent bb5344f commit 5d5ab5b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

server/src/test/java/org/elasticsearch/common/util/concurrent/ListenableFutureTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void testAddedListenersReleasedOnCompletion() {
150150
reachabilityChecker.ensureUnreachable();
151151
}
152152

153-
public void testRejection() throws Exception {
153+
public void testRejection() {
154154
final CyclicBarrier barrier = new CyclicBarrier(2);
155155
final EsThreadPoolExecutor executorService = EsExecutors.newFixed(
156156
"testRejection",
@@ -163,15 +163,11 @@ public void testRejection() throws Exception {
163163

164164
try {
165165
executorService.execute(() -> {
166-
try {
167-
barrier.await(10, TimeUnit.SECONDS); // notify main thread that the executor is blocked
168-
barrier.await(10, TimeUnit.SECONDS); // wait for main thread to release us
169-
} catch (Exception e) {
170-
throw new AssertionError("unexpected", e);
171-
}
166+
safeAwait(barrier); // notify main thread that the executor is blocked
167+
safeAwait(barrier); // wait for main thread to release us
172168
});
173169

174-
barrier.await(10, TimeUnit.SECONDS); // wait for executor to be blocked
170+
safeAwait(barrier); // wait for executor to be blocked
175171

176172
final var listenableFuture = new ListenableFuture<Void>();
177173
final var future1 = new PlainActionFuture<Void>();
@@ -190,7 +186,7 @@ public void testRejection() throws Exception {
190186
assertFalse(future1.isDone()); // still waiting in the executor queue
191187
assertTrue(future2.isDone()); // rejected from the executor on this thread
192188

193-
barrier.await(10, TimeUnit.SECONDS); // release blocked executor
189+
safeAwait(barrier); // release blocked executor
194190

195191
if (success) {
196192
expectThrows(EsRejectedExecutionException.class, future2::result);

0 commit comments

Comments
 (0)