Skip to content

Commit

Permalink
Merge pull request #10947 from jetty/fix/jetty-12/10943/flaky-Reserve…
Browse files Browse the repository at this point in the history
…dThreadExecutorTest.testBusyEvict

Fixes #10943 - Flaky test ReservedThreadExecutorTest.testBusyEvict.
  • Loading branch information
sbordet authored Nov 30, 2023
2 parents 80b1602 + 5d355ef commit 01b46aa
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Awaitility.waitAtMost;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
Expand Down Expand Up @@ -200,12 +201,41 @@ public void testBusyEvict() throws Exception
int available = _reservedExecutor.getAvailable();
assertThat(available, is(2));

for (int i = 10; i-- > 0;)
CountDownLatch latch = new CountDownLatch(1);
assertThat(_reservedExecutor.tryExecute(() ->
{
try
{
latch.await();
}
catch (InterruptedException e)
{
throw new RuntimeException(e);
}
}), is(true));

// Submit tasks for a period of one idle timeout.
// One reserved thread is busy above waiting on the
// latch, while this reserved thread will be on/off
// busy with short tasks. It will not be evicted
// because it is the only available reserved thread.
for (int i = 0; i < 10; i++)
{
Thread.sleep(IDLE / 10);
assertThat(_reservedExecutor.tryExecute(NOOP), is(true));
waitAtMost(10, SECONDS).until(_reservedExecutor::getAvailable, greaterThan(0));
}
assertThat(_reservedExecutor.getAvailable(), is(1));
waitAtMost(10, SECONDS).until(_reservedExecutor::getAvailable, is(1));

latch.countDown();

// The reserved thread that run the task that
// awaited must have been immediately evicted,
// because the other threads is available and
// reserved threads are aggressively evicted.
await()
.atLeast(IDLE / 4, MILLISECONDS)
.atMost(10, SECONDS)
.until(_reservedExecutor::getAvailable, is(1));
}

@Test
Expand Down

0 comments on commit 01b46aa

Please sign in to comment.