Browse Source

Try to stabilize RestarterTests.testRestart

Closes gh-26900
pull/27348/head
Andy Wilkinson 5 years ago
parent
commit
32effdba0a
  1. 13
      spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java

13
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@ -18,10 +18,12 @@ package org.springframework.boot.devtools.restart; @@ -18,10 +18,12 @@ package org.springframework.boot.devtools.restart;
import java.net.URL;
import java.net.URLClassLoader;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ThreadFactory;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -80,10 +82,11 @@ class RestarterTests { @@ -80,10 +82,11 @@ class RestarterTests {
Restarter.clearInstance();
Thread thread = new Thread(SampleApplication::main);
thread.start();
Thread.sleep(2600);
assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 0")).isGreaterThan(1);
assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 1")).isGreaterThan(1);
assertThat(CloseCountingApplicationListener.closed).isGreaterThan(0);
Awaitility.await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> {
assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 0")).isGreaterThan(1);
assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 1")).isGreaterThan(1);
assertThat(CloseCountingApplicationListener.closed).isGreaterThan(0);
});
}
@Test

Loading…
Cancel
Save