Skip to content

Commit 9796af7

Browse files
committed
Improve JettySockJsIntegrationTests to show real error
In a recent CI build failure a test timed out waiting for a message: https://build.spring.io/browse/SPR-PUB-1316 In fact there was a WebSocket transport failure originating in Jetty's WebSocket Parser. However this failure is only apparent by looking at the logs. This change adds a check if a transport error ocurred while we were waiting and throws an AssertionError.
1 parent a3fa9c9 commit 9796af7

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import static org.junit.Assert.assertThat;
6565
import static org.junit.Assert.assertTrue;
6666
import static org.hamcrest.Matchers.*;
67+
import static org.junit.Assert.fail;
6768

6869
/**
6970
* Integration tests using the
@@ -296,6 +297,8 @@ private static class TestClientHandler extends TextWebSocketHandler {
296297

297298
private volatile WebSocketSession session;
298299

300+
private volatile Throwable transportError;
301+
299302
private volatile CloseStatus closeStatus;
300303

301304

@@ -309,6 +312,11 @@ protected void handleTextMessage(WebSocketSession session, TextMessage message)
309312
this.receivedMessages.add(message);
310313
}
311314

315+
@Override
316+
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
317+
this.transportError = exception;
318+
}
319+
312320
@Override
313321
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
314322
this.closeStatus = status;
@@ -321,12 +329,22 @@ public void awaitMessageCount(final int count, long timeToWait) throws Exception
321329

322330
public void awaitMessage(TextMessage expected, long timeToWait) throws InterruptedException {
323331
TextMessage actual = this.receivedMessages.poll(timeToWait, TimeUnit.MILLISECONDS);
324-
assertNotNull("Timed out waiting for [" + expected + "]", actual);
325-
assertEquals(expected, actual);
332+
if (actual != null) {
333+
assertEquals(expected, actual);
334+
}
335+
else if (this.transportError != null) {
336+
throw new AssertionError("Transport error", this.transportError);
337+
}
338+
else {
339+
fail("Timed out waiting for [" + expected + "]");
340+
}
326341
}
327342

328343
public CloseStatus awaitCloseStatus(long timeToWait) throws InterruptedException {
329-
awaitEvent(() -> this.closeStatus != null, timeToWait, " CloseStatus");
344+
awaitEvent(() -> this.closeStatus != null || this.transportError != null, timeToWait, " CloseStatus");
345+
if (this.transportError != null) {
346+
throw new AssertionError("Transport error", this.transportError);
347+
}
330348
return this.closeStatus;
331349
}
332350
}

0 commit comments

Comments
 (0)