ok2c commented on PR #649:
URL:
https://github.com/apache/httpcomponents-core/pull/649#issuecomment-4013162004
@arturobernalg Can we also try to get this test case to work?
Interestingly enough, `OFFLOCK` is the only pool implementation that appears
to be able to handle the test correctly. Kudos to you, But it can also be my
test case is flawed, so let's be diligent.
```
@ParameterizedTest(name = "{0}")
@MethodSource("pools")
@org.junit.jupiter.api.Timeout(60)
void testInterruptDoesNotLeakLeasedEntries(final PoolCase poolCase)
throws Exception {
final ManagedConnPool<String, DummyConn> pool =
poolCase.supplier.get();
final String route = "route-1";
final int concurrentThreads = 10;
final ExecutorService executorService =
Executors.newFixedThreadPool(concurrentThreads);
final AtomicReference<Exception> unexpectedException = new
AtomicReference<>();
try {
final Queue<Future<?>> taskQueue = new ConcurrentLinkedQueue<>();
for (int i = 0; i < concurrentThreads * 100; i++) {
taskQueue.add(executorService.submit(() -> {
final Future<PoolEntry<String, DummyConn>> f =
pool.lease(route, null, TIMEOUT, null);
try {
final PoolEntry<String, DummyConn> entry =
f.get(TIMEOUT.getDuration(),
TIMEOUT.getTimeUnit());
pool.release(entry, true);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (final ExecutionException | TimeoutException ex)
{
f.cancel(true);
unexpectedException.compareAndSet(null, ex);
}
}));
}
for (;;) {
final Future<?> future = taskQueue.poll();
if (future != null) {
future.cancel(true);
} else {
break;
}
}
executorService.shutdown();
Assertions.assertTrue(executorService.awaitTermination(TIMEOUT.getDuration(),
TIMEOUT.getTimeUnit()));
Assertions.assertNull(unexpectedException.get());
final PoolStats stats = pool.getStats(route);
Assertions.assertEquals(0, stats.getLeased());
} finally {
executorService.shutdownNow();
pool.close(CloseMode.GRACEFUL);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]