Merge pull request #21988 from tszmytka
* gh-21988: Polish "Use Awaitility instead of Thread.sleep" Use Awaitility instead of Thread.sleep Closes gh-21988
This commit is contained in:
commit
f656083007
|
|
@ -23,6 +23,7 @@ import java.net.URI;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
@ -45,6 +46,7 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.awaitility.Awaitility.await;
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
|
|
@ -88,17 +90,18 @@ class LiveReloadServerTests {
|
||||||
void triggerReload() throws Exception {
|
void triggerReload() throws Exception {
|
||||||
LiveReloadWebSocketHandler handler = connect();
|
LiveReloadWebSocketHandler handler = connect();
|
||||||
this.server.triggerReload();
|
this.server.triggerReload();
|
||||||
Thread.sleep(200);
|
List<String> messages = await().atMost(Duration.ofSeconds(10)).until(handler::getMessages,
|
||||||
assertThat(handler.getMessages().get(0)).contains("http://livereload.com/protocols/official-7");
|
(msgs) -> msgs.size() == 2);
|
||||||
assertThat(handler.getMessages().get(1)).contains("command\":\"reload\"");
|
assertThat(messages.get(0)).contains("http://livereload.com/protocols/official-7");
|
||||||
|
assertThat(messages.get(1)).contains("command\":\"reload\"");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pingPong() throws Exception {
|
void pingPong() throws Exception {
|
||||||
LiveReloadWebSocketHandler handler = connect();
|
LiveReloadWebSocketHandler handler = connect();
|
||||||
handler.sendMessage(new PingMessage());
|
handler.sendMessage(new PingMessage());
|
||||||
Thread.sleep(200);
|
await().atMost(Duration.ofSeconds(10)).until(handler::getPongCount, is(1));
|
||||||
assertThat(handler.getPongCount()).isEqualTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -117,8 +120,9 @@ class LiveReloadServerTests {
|
||||||
void serverClose() throws Exception {
|
void serverClose() throws Exception {
|
||||||
LiveReloadWebSocketHandler handler = connect();
|
LiveReloadWebSocketHandler handler = connect();
|
||||||
this.server.stop();
|
this.server.stop();
|
||||||
Thread.sleep(200);
|
CloseStatus closeStatus = await().atMost(Duration.ofSeconds(10)).until(handler::getCloseStatus,
|
||||||
assertThat(handler.getCloseStatus().getCode()).isEqualTo(1006);
|
Objects::nonNull);
|
||||||
|
assertThat(closeStatus.getCode()).isEqualTo(1006);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LiveReloadWebSocketHandler connect() throws Exception {
|
private LiveReloadWebSocketHandler connect() throws Exception {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue