Skip to content

Commit 7ba575d

Browse files
committed
Prevent RestarterTests.testRestart from triggering unwanted restarts
See gh-26900
1 parent 32effdb commit 7ba575d

File tree

1 file changed

+3
-15
lines changed
  • spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart

1 file changed

+3
-15
lines changed

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Collection;
2323
import java.util.Collections;
2424
import java.util.concurrent.ThreadFactory;
25+
import java.util.concurrent.atomic.AtomicBoolean;
2526

2627
import org.awaitility.Awaitility;
2728
import org.junit.jupiter.api.AfterEach;
@@ -177,7 +178,7 @@ static class SampleApplication {
177178

178179
private int count = 0;
179180

180-
private static volatile boolean quit = false;
181+
private static final AtomicBoolean restart = new AtomicBoolean();
181182

182183
@Scheduled(fixedDelay = 200)
183184
void tickBean() {
@@ -186,8 +187,7 @@ void tickBean() {
186187

187188
@Scheduled(initialDelay = 500, fixedDelay = 500)
188189
void restart() {
189-
System.out.println("Restart " + Thread.currentThread());
190-
if (!SampleApplication.quit) {
190+
if (SampleApplication.restart.compareAndSet(false, true)) {
191191
Restarter.getInstance().restart();
192192
}
193193
}
@@ -198,18 +198,6 @@ static void main(String... args) {
198198
SampleApplication.class);
199199
context.addApplicationListener(new CloseCountingApplicationListener());
200200
Restarter.getInstance().prepare(context);
201-
System.out.println("Sleep " + Thread.currentThread());
202-
sleep();
203-
quit = true;
204-
}
205-
206-
private static void sleep() {
207-
try {
208-
Thread.sleep(1200);
209-
}
210-
catch (InterruptedException ex) {
211-
// Ignore
212-
}
213201
}
214202

215203
}

0 commit comments

Comments
 (0)