Skip to content

Commit 2990591

Browse files
committed
Update test
1 parent 4b5836b commit 2990591

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPoolLeaseTimeoutRace.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
import java.util.concurrent.ExecutorService;
3333
import java.util.concurrent.Executors;
3434
import java.util.concurrent.Future;
35-
import java.util.concurrent.TimeUnit;
3635
import java.util.concurrent.TimeoutException;
3736
import java.util.concurrent.atomic.AtomicLong;
37+
import java.util.concurrent.atomic.AtomicReference;
3838
import java.util.function.Supplier;
3939
import java.util.stream.Stream;
4040

@@ -115,6 +115,7 @@ void testLeaseTimeoutDoesNotLeakLeasedEntries(final PoolCase poolCase) throws Ex
115115
final AtomicLong n = new AtomicLong(concurrentThreads * 100);
116116

117117
final ExecutorService executorService = Executors.newFixedThreadPool(concurrentThreads);
118+
final AtomicReference<Exception> unexpectedException = new AtomicReference<>();
118119
try {
119120
for (int i = 0; i < concurrentThreads; i++) {
120121
executorService.execute(() -> {
@@ -127,9 +128,14 @@ void testLeaseTimeoutDoesNotLeakLeasedEntries(final PoolCase poolCase) throws Ex
127128
pool.release(entry, true);
128129
} catch (final InterruptedException ex) {
129130
Thread.currentThread().interrupt();
130-
Assertions.fail("Unexpected exception", ex);
131-
} catch (final TimeoutException | ExecutionException ignored) {
131+
unexpectedException.compareAndSet(null, ex);
132+
} catch (final TimeoutException ex) {
132133
f.cancel(true);
134+
} catch (final ExecutionException ex) {
135+
f.cancel(true);
136+
if (!(ex.getCause() instanceof TimeoutException)) {
137+
unexpectedException.compareAndSet(null, ex);
138+
}
133139
}
134140
}
135141
} finally {
@@ -140,13 +146,14 @@ void testLeaseTimeoutDoesNotLeakLeasedEntries(final PoolCase poolCase) throws Ex
140146

141147
Assertions.assertTrue(countDownLatch.await(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()));
142148
Assertions.assertTrue(n.get() <= 0);
149+
Assertions.assertNull(unexpectedException.get());
143150

144151
final PoolStats stats = pool.getStats(route);
145152
Assertions.assertEquals(0, stats.getLeased());
146153

147154
} finally {
148155
executorService.shutdownNow();
149-
executorService.awaitTermination(5, TimeUnit.SECONDS);
156+
executorService.awaitTermination(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
150157
pool.close(CloseMode.GRACEFUL);
151158
}
152159
}

0 commit comments

Comments
 (0)