Skip to content

Commit 6fb6292

Browse files
committed
Fix race condition in SampleQuartzApplicationTests
1 parent 87182a3 commit 6fb6292

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ public class SampleQuartzApplicationTests {
3636
public OutputCapture outputCapture = new OutputCapture();
3737

3838
@Test
39-
public void test() {
40-
try (ConfigurableApplicationContext context = SpringApplication.run(
41-
SampleQuartzApplication.class)) {
42-
String output = this.outputCapture.toString();
43-
assertThat(output).contains("Hello World!");
39+
public void quartzJobIsTriggered() throws InterruptedException {
40+
try (ConfigurableApplicationContext context = SpringApplication
41+
.run(SampleQuartzApplication.class)) {
42+
long end = System.currentTimeMillis() + 5000;
43+
while ((!this.outputCapture.toString().contains("Hello World!"))
44+
&& System.currentTimeMillis() < end) {
45+
Thread.sleep(100);
46+
}
47+
assertThat(this.outputCapture.toString()).contains("Hello World!");
4448
}
4549
}
4650

0 commit comments

Comments
 (0)