Fix DelayHandlerTests timing issue

https://build.spring.io/browse/INT-MASTER-1042

The `verifyShutdownWithWait()` test uses extra thread for waiting for
the `TaskScheduler` to finish its tasks.
Also the test doesn't verify the actual behavior at all

* Move `awaitTermination()` to the assert
* Decrease `delay` for the message
* Assert the latch from the handler to be sure that message is scheduled
properly even if `destroy()` call, thanks to required
`waitForTasksToCompleteOnShutdown = true`
This commit is contained in:
Artem Bilan
2018-05-16 15:17:01 -04:00
parent 549ef87a8e
commit 7113236e24

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -254,24 +254,14 @@ public class DelayHandlerTests {
@Test @Test
public void verifyShutdownWithWait() throws Exception { public void verifyShutdownWithWait() throws Exception {
delayHandler.setDefaultDelay(5000); this.delayHandler.setDefaultDelay(100);
taskScheduler.setWaitForTasksToCompleteOnShutdown(true); this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.startDelayerHandler(); startDelayerHandler();
delayHandler.handleMessage(new GenericMessage<String>("foo")); this.delayHandler.handleMessage(new GenericMessage<>("foo"));
taskScheduler.destroy(); this.taskScheduler.destroy();
final CountDownLatch latch = new CountDownLatch(1); assertTrue(this.taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS));
new Thread(() -> { assertTrue(this.latch.await(10, TimeUnit.SECONDS));
try {
taskScheduler.getScheduledExecutor().awaitTermination(10000, TimeUnit.MILLISECONDS);
latch.countDown();
}
catch (InterruptedException e) {
// won't countDown
}
}).start();
latch.await(50, TimeUnit.MILLISECONDS);
assertEquals(1, latch.getCount());
} }
@Test(expected = MessageDeliveryException.class) @Test(expected = MessageDeliveryException.class)