Skip to content

Commit 0d78ff0

Browse files
committed
Polish "Use a timeout when joining threads in HttpTunnelServerTests"
See gh-29522
1 parent 940d969 commit 0d78ff0

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerTests.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,6 +65,8 @@ class HttpTunnelServerTests {
6565

6666
private static final int DEFAULT_LONG_POLL_TIMEOUT = 10000;
6767

68+
private static final int JOIN_TIMEOUT = 5000;
69+
6870
private static final byte[] NO_DATA = {};
6971

7072
private static final String SEQ_HEADER = "x-seq";
@@ -130,7 +132,7 @@ void initialRequestIsSentToServer() throws Exception {
130132
this.servletRequest.setContent("hello".getBytes());
131133
this.server.handle(this.request, this.response);
132134
this.serverChannel.disconnect();
133-
this.server.getServerThread().join(2000);
135+
this.server.getServerThread().join(JOIN_TIMEOUT);
134136
this.serverChannel.verifyReceived("hello");
135137
}
136138

@@ -143,7 +145,7 @@ void initialRequestIsUsedForFirstServerResponse() throws Exception {
143145
System.out.println("sending");
144146
this.serverChannel.send("hello");
145147
this.serverChannel.disconnect();
146-
this.server.getServerThread().join(2000);
148+
this.server.getServerThread().join(JOIN_TIMEOUT);
147149
assertThat(this.servletResponse.getContentAsString()).isEqualTo("hello");
148150
this.serverChannel.verifyReceived("hello");
149151
}
@@ -153,7 +155,7 @@ void initialRequestHasNoPayload() throws Exception {
153155
givenServerConnectionOpenWillAnswerWithServerChannel();
154156
this.server.handle(this.request, this.response);
155157
this.serverChannel.disconnect();
156-
this.server.getServerThread().join(2000);
158+
this.server.getServerThread().join(JOIN_TIMEOUT);
157159
this.serverChannel.verifyReceived(NO_DATA);
158160
}
159161

@@ -176,7 +178,7 @@ void typicalRequestResponseTraffic() throws Exception {
176178
this.serverChannel.send("=3");
177179
h3.verifyReceived("=3", 3);
178180
this.serverChannel.disconnect();
179-
this.server.getServerThread().join(2000);
181+
this.server.getServerThread().join(JOIN_TIMEOUT);
180182
}
181183

182184
@Test
@@ -185,7 +187,7 @@ void clientIsAwareOfServerClose() throws Exception {
185187
MockHttpConnection h1 = new MockHttpConnection("1", 1);
186188
this.server.handle(h1);
187189
this.serverChannel.disconnect();
188-
this.server.getServerThread().join(2000);
190+
this.server.getServerThread().join(JOIN_TIMEOUT);
189191
assertThat(h1.getServletResponse().getStatus()).isEqualTo(410);
190192
}
191193

@@ -197,7 +199,7 @@ void clientCanCloseServer() throws Exception {
197199
MockHttpConnection h2 = new MockHttpConnection("DISCONNECT", 1);
198200
h2.getServletRequest().addHeader("Content-Type", "application/x-disconnect");
199201
this.server.handle(h2);
200-
this.server.getServerThread().join(2000);
202+
this.server.getServerThread().join(JOIN_TIMEOUT);
201203
assertThat(h1.getServletResponse().getStatus()).isEqualTo(410);
202204
assertThat(this.serverChannel.isOpen()).isFalse();
203205
}
@@ -214,7 +216,7 @@ void neverMoreThanTwoHttpConnections() throws Exception {
214216
h1.waitForResponse();
215217
assertThat(h1.getServletResponse().getStatus()).isEqualTo(429);
216218
this.serverChannel.disconnect();
217-
this.server.getServerThread().join(2000);
219+
this.server.getServerThread().join(JOIN_TIMEOUT);
218220
}
219221

220222
@Test
@@ -228,7 +230,7 @@ void requestReceivedOutOfOrder() throws Exception {
228230
this.server.handle(h2);
229231
this.serverChannel.verifyReceived("1+2+3");
230232
this.serverChannel.disconnect();
231-
this.server.getServerThread().join(2000);
233+
this.server.getServerThread().join(JOIN_TIMEOUT);
232234
}
233235

234236
@Test
@@ -245,7 +247,7 @@ void httpConnectionsAreClosedAfterLongPollTimeout() throws Exception {
245247
Awaitility.await().atMost(Duration.ofSeconds(30)).until(h2.getServletResponse()::getStatus,
246248
(status) -> status == 204);
247249
this.serverChannel.disconnect();
248-
this.server.getServerThread().join(2000);
250+
this.server.getServerThread().join(JOIN_TIMEOUT);
249251
}
250252

251253
@Test
@@ -256,7 +258,7 @@ void disconnectTimeout() throws Exception {
256258
MockHttpConnection h1 = new MockHttpConnection();
257259
this.server.handle(h1);
258260
this.serverChannel.send("hello");
259-
this.server.getServerThread().join(2000);
261+
this.server.getServerThread().join(JOIN_TIMEOUT);
260262
assertThat(this.serverChannel.isOpen()).isFalse();
261263
}
262264

0 commit comments

Comments
 (0)