Skip to content

Commit

Permalink
#9622 replace wait loops with awaitility and ensure the tested value…
Browse files Browse the repository at this point in the history
…s are stable for a certain duration

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Apr 5, 2023
1 parent 642ce81 commit 9ff24ea
Showing 1 changed file with 4 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public void testEvict() throws Exception
}

waitForThreads(tp, 10);
waitForIdle(tp, 0);
waitForIdle(tp, 2);

sleep.set(5);
for (int i = 0; i < 500; i++)
Expand Down Expand Up @@ -700,51 +700,17 @@ public void testMaxStopTime() throws Exception

private void waitForIdle(QueuedThreadPool tp, int idle)
{
long start = NanoTime.now();
while (tp.getIdleThreads() != idle && NanoTime.millisSince(start) < 10000)
{
try
{
Thread.sleep(50);
}
catch (InterruptedException ignored)
{
}
}
assertThat(tp.getIdleThreads(), is(idle));
await().during(100, TimeUnit.MILLISECONDS).atMost(10, TimeUnit.SECONDS).until(tp::getIdleThreads, is(idle));
}

private void waitForReserved(QueuedThreadPool tp, int reserved)
{
long start = NanoTime.now();
ReservedThreadExecutor reservedThreadExecutor = tp.getBean(ReservedThreadExecutor.class);
while (reservedThreadExecutor.getAvailable() != reserved && NanoTime.millisSince(start) < 10000)
{
try
{
Thread.sleep(50);
}
catch (InterruptedException ignored)
{
}
}
assertThat(reservedThreadExecutor.getAvailable(), is(reserved));
await().during(100, TimeUnit.MILLISECONDS).atMost(10, TimeUnit.SECONDS).until(() -> tp.getBean(ReservedThreadExecutor.class).getAvailable(), is(reserved));
}

private void waitForThreads(QueuedThreadPool tp, int threads)
{
long start = NanoTime.now();
while (tp.getThreads() != threads && NanoTime.millisSince(start) < 10000)
{
try
{
Thread.sleep(50);
}
catch (InterruptedException ignored)
{
}
}
assertThat(tp.getThreads(), is(threads));
await().during(100, TimeUnit.MILLISECONDS).atMost(10, TimeUnit.SECONDS).until(tp::getThreads, is(threads));
}

@Test
Expand Down

0 comments on commit 9ff24ea

Please sign in to comment.