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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
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 ();
261+ this .server .getServerThread ().join (JOIN_TIMEOUT );
260262 assertThat (this .serverChannel .isOpen ()).isFalse ();
261263 }
262264
0 commit comments