Skip to content

Commit 988499f

Browse files
committed
Remove awaitCloseStatus in SockJS integration tests
A CloseStatus may not be received if the connection is closed while the client is between XHR polling requests.
1 parent 6c4aff4 commit 988499f

File tree

1 file changed

+7
-36
lines changed

1 file changed

+7
-36
lines changed

spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21-
import org.hamcrest.Matchers;
2221
import org.junit.After;
2322
import org.junit.Before;
2423
import org.junit.Ignore;
@@ -31,7 +30,6 @@
3130
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
3231
import org.springframework.util.concurrent.ListenableFutureCallback;
3332
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
34-
import org.springframework.web.socket.CloseStatus;
3533
import org.springframework.web.socket.TextMessage;
3634
import org.springframework.web.socket.WebSocketSession;
3735
import org.springframework.web.socket.WebSocketTestServer;
@@ -64,9 +62,7 @@
6462

6563
import static org.junit.Assert.assertEquals;
6664
import static org.junit.Assert.assertNotNull;
67-
import static org.junit.Assert.assertThat;
6865
import static org.junit.Assert.assertTrue;
69-
import static org.hamcrest.Matchers.*;
7066
import static org.junit.Assert.fail;
7167

7268
/**
@@ -166,20 +162,20 @@ public void echoXhr() throws Exception {
166162

167163
@Ignore
168164
@Test
169-
public void closeAfterOneMessageWebSocket() throws Exception {
170-
testCloseAfterOneMessage(createWebSocketTransport());
165+
public void receiveOneMessageWebSocket() throws Exception {
166+
testReceiveOneMessage(createWebSocketTransport());
171167
}
172168

173169
@Test
174-
public void closeAfterOneMessageXhrStreaming() throws Exception {
175-
testCloseAfterOneMessage(createXhrTransport());
170+
public void receiveOneMessageXhrStreaming() throws Exception {
171+
testReceiveOneMessage(createXhrTransport());
176172
}
177173

178174
@Test
179-
public void closeAfterOneMessageXhr() throws Exception {
175+
public void receiveOneMessageXhr() throws Exception {
180176
AbstractXhrTransport xhrTransport = createXhrTransport();
181177
xhrTransport.setXhrStreamingDisabled(true);
182-
testCloseAfterOneMessage(xhrTransport);
178+
testReceiveOneMessage(xhrTransport);
183179
}
184180

185181
@Test
@@ -251,7 +247,7 @@ private void testEcho(int messageCount, Transport transport) throws Exception {
251247
session.close();
252248
}
253249

254-
private void testCloseAfterOneMessage(Transport transport) throws Exception {
250+
private void testReceiveOneMessage(Transport transport) throws Exception {
255251
TestClientHandler clientHandler = new TestClientHandler();
256252
initSockJsClient(transport);
257253
this.sockJsClient.doHandshake(clientHandler, this.baseUrl + "/test").get();
@@ -263,16 +259,6 @@ private void testCloseAfterOneMessage(Transport transport) throws Exception {
263259
TextMessage message = new TextMessage("message1");
264260
serverHandler.session.sendMessage(message);
265261
clientHandler.awaitMessage(message, 5000);
266-
267-
CloseStatus expected = new CloseStatus(3500, "Oops");
268-
serverHandler.session.close(expected);
269-
CloseStatus actual = clientHandler.awaitCloseStatus(5000);
270-
if (transport instanceof XhrTransport) {
271-
assertThat(actual, Matchers.anyOf(equalTo(expected), equalTo(new CloseStatus(3000, "Go away!"))));
272-
}
273-
else {
274-
assertEquals(expected, actual);
275-
}
276262
}
277263

278264

@@ -324,8 +310,6 @@ private static class TestClientHandler extends TextWebSocketHandler {
324310

325311
private volatile Throwable transportError;
326312

327-
private volatile CloseStatus closeStatus;
328-
329313

330314
@Override
331315
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
@@ -342,11 +326,6 @@ public void handleTransportError(WebSocketSession session, Throwable exception)
342326
this.transportError = exception;
343327
}
344328

345-
@Override
346-
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
347-
this.closeStatus = status;
348-
}
349-
350329
public void awaitMessageCount(final int count, long timeToWait) throws Exception {
351330
awaitEvent(() -> receivedMessages.size() >= count, timeToWait,
352331
count + " number of messages. Received so far: " + this.receivedMessages);
@@ -364,14 +343,6 @@ else if (this.transportError != null) {
364343
fail("Timed out waiting for [" + expected + "]");
365344
}
366345
}
367-
368-
public CloseStatus awaitCloseStatus(long timeToWait) throws InterruptedException {
369-
awaitEvent(() -> this.closeStatus != null || this.transportError != null, timeToWait, " CloseStatus");
370-
if (this.transportError != null) {
371-
throw new AssertionError("Transport error", this.transportError);
372-
}
373-
return this.closeStatus;
374-
}
375346
}
376347

377348
private static class TestServerHandler extends TextWebSocketHandler {

0 commit comments

Comments
 (0)