Skip to content

Commit 41173f7

Browse files
committed
Polish "Use Awaitility instead of Thread.sleep"
See gh-21988
1 parent c13385e commit 41173f7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.time.Duration;
2424
import java.util.ArrayList;
2525
import java.util.List;
26+
import java.util.Objects;
2627
import java.util.concurrent.CountDownLatch;
2728
import java.util.concurrent.TimeUnit;
2829

@@ -89,16 +90,18 @@ void servesLivereloadJs() throws Exception {
8990
void triggerReload() throws Exception {
9091
LiveReloadWebSocketHandler handler = connect();
9192
this.server.triggerReload();
92-
await().atMost(Duration.ofSeconds(1)).until(handler::getMessages,
93-
(msgs) -> msgs.get(0).contains("http://livereload.com/protocols/official-7")
94-
&& msgs.get(1).contains("command\":\"reload\""));
93+
List<String> messages = await().atMost(Duration.ofSeconds(10)).until(handler::getMessages,
94+
(msgs) -> msgs.size() == 2);
95+
assertThat(messages.get(0)).contains("http://livereload.com/protocols/official-7");
96+
assertThat(messages.get(1)).contains("command\":\"reload\"");
97+
9598
}
9699

97100
@Test
98101
void pingPong() throws Exception {
99102
LiveReloadWebSocketHandler handler = connect();
100103
handler.sendMessage(new PingMessage());
101-
await().atMost(Duration.ofSeconds(1)).until(handler::getPongCount, is(1));
104+
await().atMost(Duration.ofSeconds(10)).until(handler::getPongCount, is(1));
102105
}
103106

104107
@Test
@@ -117,7 +120,9 @@ private void awaitClosedException() throws InterruptedException {
117120
void serverClose() throws Exception {
118121
LiveReloadWebSocketHandler handler = connect();
119122
this.server.stop();
120-
await().atMost(Duration.ofSeconds(1)).until(() -> handler.getCloseStatus().getCode(), is(1006));
123+
CloseStatus closeStatus = await().atMost(Duration.ofSeconds(10)).until(handler::getCloseStatus,
124+
Objects::nonNull);
125+
assertThat(closeStatus.getCode()).isEqualTo(1006);
121126
}
122127

123128
private LiveReloadWebSocketHandler connect() throws Exception {

0 commit comments

Comments
 (0)