From 7aa848927961805968f0015f7d20268ccfe2d61e Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 19 Oct 2018 15:42:31 -0400 Subject: [PATCH] Fix race in PollingLifecycleTests --- .../integration/endpoint/PollingLifecycleTests.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingLifecycleTests.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingLifecycleTests.java index 58c04f17c2..428f7b2e30 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingLifecycleTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollingLifecycleTests.java @@ -52,6 +52,7 @@ import org.springframework.scheduling.support.PeriodicTrigger; * @author Oleg Zhurakousky * @author Gunnar Hillert * @author Artem Bilan + * @author Gary Russell */ public class PollingLifecycleTests { @@ -144,16 +145,18 @@ public class PollingLifecycleTests { pollerMetadata.setTrigger(new PeriodicTrigger(2000)); adapterFactory.setPollerMetadata(pollerMetadata); final Runnable caughtInterrupted = mock(Runnable.class); + final CountDownLatch interruptedLatch = new CountDownLatch(1); MessageSource source = () -> { try { for (int i = 0; i < 10; i++) { - Thread.sleep(10); + Thread.sleep(latch.getCount() > 0 ? 10 : 1000); latch.countDown(); } } catch (InterruptedException e) { caughtInterrupted.run(); + interruptedLatch.countDown(); } return new GenericMessage<>("hello"); @@ -165,10 +168,10 @@ public class PollingLifecycleTests { adapter.setTaskScheduler(taskScheduler); adapter.afterPropertiesSet(); adapter.start(); - assertTrue(latch.await(3000, TimeUnit.SECONDS)); + assertTrue(latch.await(10_000, TimeUnit.SECONDS)); // adapter.stop(); - Thread.sleep(10); + assertTrue(interruptedLatch.await(10_000, TimeUnit.SECONDS)); Mockito.verify(caughtInterrupted, times(1)).run(); }