From 7113236e24a0d254749c31334d494ca2843febfd Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 16 May 2018 15:17:01 -0400 Subject: [PATCH] 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` --- .../handler/DelayHandlerTests.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/DelayHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/DelayHandlerTests.java index f455822d73..19e459423b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/DelayHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/DelayHandlerTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -254,24 +254,14 @@ public class DelayHandlerTests { @Test public void verifyShutdownWithWait() throws Exception { - delayHandler.setDefaultDelay(5000); - taskScheduler.setWaitForTasksToCompleteOnShutdown(true); - this.startDelayerHandler(); - delayHandler.handleMessage(new GenericMessage("foo")); - taskScheduler.destroy(); + this.delayHandler.setDefaultDelay(100); + this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true); + startDelayerHandler(); + this.delayHandler.handleMessage(new GenericMessage<>("foo")); + this.taskScheduler.destroy(); - final CountDownLatch latch = new CountDownLatch(1); - new Thread(() -> { - 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()); + assertTrue(this.taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS)); + assertTrue(this.latch.await(10, TimeUnit.SECONDS)); } @Test(expected = MessageDeliveryException.class)