#9622 replace wait loops with awaitility and ensure the tested values are stable for a certain duration

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2023-04-04 10:45:29 +02:00
parent 642ce818ae
commit 9ff24ea443
1 changed files with 4 additions and 38 deletions

View File

@ -546,7 +546,7 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest
} }
waitForThreads(tp, 10); waitForThreads(tp, 10);
waitForIdle(tp, 0); waitForIdle(tp, 2);
sleep.set(5); sleep.set(5);
for (int i = 0; i < 500; i++) for (int i = 0; i < 500; i++)
@ -700,51 +700,17 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest
private void waitForIdle(QueuedThreadPool tp, int idle) private void waitForIdle(QueuedThreadPool tp, int idle)
{ {
long start = NanoTime.now(); await().during(100, TimeUnit.MILLISECONDS).atMost(10, TimeUnit.SECONDS).until(tp::getIdleThreads, is(idle));
while (tp.getIdleThreads() != idle && NanoTime.millisSince(start) < 10000)
{
try
{
Thread.sleep(50);
}
catch (InterruptedException ignored)
{
}
}
assertThat(tp.getIdleThreads(), is(idle));
} }
private void waitForReserved(QueuedThreadPool tp, int reserved) private void waitForReserved(QueuedThreadPool tp, int reserved)
{ {
long start = NanoTime.now(); await().during(100, TimeUnit.MILLISECONDS).atMost(10, TimeUnit.SECONDS).until(() -> tp.getBean(ReservedThreadExecutor.class).getAvailable(), is(reserved));
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));
} }
private void waitForThreads(QueuedThreadPool tp, int threads) private void waitForThreads(QueuedThreadPool tp, int threads)
{ {
long start = NanoTime.now(); await().during(100, TimeUnit.MILLISECONDS).atMost(10, TimeUnit.SECONDS).until(tp::getThreads, is(threads));
while (tp.getThreads() != threads && NanoTime.millisSince(start) < 10000)
{
try
{
Thread.sleep(50);
}
catch (InterruptedException ignored)
{
}
}
assertThat(tp.getThreads(), is(threads));
} }
@Test @Test