From d9be281ffff54225e7e79bdb054c13a4e5f16c93 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 17 Dec 2019 17:00:01 -0500 Subject: [PATCH] Fix intermittent --- .../jpa/sched/SchedulerServiceImplTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java index de008af9646..4db538ce048 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java @@ -25,7 +25,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.util.AopTestUtils; import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; -import static org.hamcrest.Matchers.*; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; @@ -34,10 +37,9 @@ import static org.junit.Assert.fail; public class SchedulerServiceImplTest { private static final Logger ourLog = LoggerFactory.getLogger(SchedulerServiceImplTest.class); - + private static long ourTaskDelay; @Autowired private ISchedulerService mySvc; - private static long ourTaskDelay; @Before public void before() { @@ -79,7 +81,7 @@ public class SchedulerServiceImplTest { ourLog.info("Fired {} times", CountingJob.ourCount); - assertThat(CountingJob.ourCount, greaterThan(3)); + await().until(() -> (CountingJob.ourCount, greaterThan(3)); assertThat(CountingJob.ourCount, lessThan(20)); } @@ -97,7 +99,7 @@ public class SchedulerServiceImplTest { ourLog.info("Fired {} times", CountingJob.ourCount); - assertThat(CountingJob.ourCount, greaterThanOrEqualTo(1)); + await().until(() -> (CountingJob.ourCount, greaterThanOrEqualTo(1)); assertThat(CountingJob.ourCount, lessThan(5)); } @@ -115,7 +117,7 @@ public class SchedulerServiceImplTest { ourLog.info("Fired {} times", CountingIntervalJob.ourCount); - assertThat(CountingIntervalJob.ourCount, greaterThanOrEqualTo(2)); + await().until(() -> CountingIntervalJob.ourCount, greaterThanOrEqualTo(2)); assertThat(CountingIntervalJob.ourCount, lessThan(6)); } @@ -171,8 +173,8 @@ public class SchedulerServiceImplTest { @Override public void execute(JobExecutionContext theContext) { - ourLog.info("Job has fired, going to sleep for {}ms", ourTaskDelay); - sleepAtLeast(ourTaskDelay); + ourLog.info("Job has fired, going to sleep for {}ms", ourTaskDelay); + sleepAtLeast(ourTaskDelay); ourCount++; } }