Test: testTimeoutCleanup use assertBusy while checking timer queue
This commit is contained in:
parent
34155ff102
commit
66e71da7bd
|
@ -244,7 +244,7 @@ public class PrioritizedExecutorsTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testTimeoutCleanup() throws Exception {
|
||||
ThreadPool threadPool = new ThreadPool("test");
|
||||
ScheduledThreadPoolExecutor timer = (ScheduledThreadPoolExecutor) threadPool.scheduler();
|
||||
final ScheduledThreadPoolExecutor timer = (ScheduledThreadPoolExecutor) threadPool.scheduler();
|
||||
final AtomicBoolean timeoutCalled = new AtomicBoolean();
|
||||
PrioritizedEsThreadPoolExecutor executor = EsExecutors.newSinglePrioritizing(EsExecutors.daemonThreadFactory(getTestName()));
|
||||
final CountDownLatch invoked = new CountDownLatch(1);
|
||||
|
@ -262,7 +262,15 @@ public class PrioritizedExecutorsTests extends ElasticsearchTestCase {
|
|||
}
|
||||
);
|
||||
invoked.await();
|
||||
assertThat(timer.getQueue().size(), equalTo(0));
|
||||
|
||||
// the timeout handler is added post execution (and quickly cancelled). We have allow for this
|
||||
// and use assert busy
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(timer.getQueue().size(), equalTo(0));
|
||||
}
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
assertThat(timeoutCalled.get(), equalTo(false));
|
||||
assertTrue(terminate(executor));
|
||||
assertTrue(terminate(threadPool));
|
||||
|
|
Loading…
Reference in New Issue