Skip to content

Commit 7113236

Browse files
committed
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`
1 parent 549ef87 commit 7113236

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

spring-integration-core/src/test/java/org/springframework/integration/handler/DelayHandlerTests.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -254,24 +254,14 @@ public void verifyShutdownWithoutWaitingByDefault() throws Exception {
254254

255255
@Test
256256
public void verifyShutdownWithWait() throws Exception {
257-
delayHandler.setDefaultDelay(5000);
258-
taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
259-
this.startDelayerHandler();
260-
delayHandler.handleMessage(new GenericMessage<String>("foo"));
261-
taskScheduler.destroy();
257+
this.delayHandler.setDefaultDelay(100);
258+
this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
259+
startDelayerHandler();
260+
this.delayHandler.handleMessage(new GenericMessage<>("foo"));
261+
this.taskScheduler.destroy();
262262

263-
final CountDownLatch latch = new CountDownLatch(1);
264-
new Thread(() -> {
265-
try {
266-
taskScheduler.getScheduledExecutor().awaitTermination(10000, TimeUnit.MILLISECONDS);
267-
latch.countDown();
268-
}
269-
catch (InterruptedException e) {
270-
// won't countDown
271-
}
272-
}).start();
273-
latch.await(50, TimeUnit.MILLISECONDS);
274-
assertEquals(1, latch.getCount());
263+
assertTrue(this.taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS));
264+
assertTrue(this.latch.await(10, TimeUnit.SECONDS));
275265
}
276266

277267
@Test(expected = MessageDeliveryException.class)

0 commit comments

Comments
 (0)