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.
This commit is contained in:
parent
a3fa9c9797
commit
9796af72db
|
|
@ -64,6 +64,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Integration tests using the
|
||||
|
|
@ -296,6 +297,8 @@ public abstract class AbstractSockJsIntegrationTests {
|
|||
|
||||
private volatile WebSocketSession session;
|
||||
|
||||
private volatile Throwable transportError;
|
||||
|
||||
private volatile CloseStatus closeStatus;
|
||||
|
||||
|
||||
|
|
@ -309,6 +312,11 @@ public abstract class AbstractSockJsIntegrationTests {
|
|||
this.receivedMessages.add(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||
this.transportError = exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
|
||||
this.closeStatus = status;
|
||||
|
|
@ -321,12 +329,22 @@ public abstract class AbstractSockJsIntegrationTests {
|
|||
|
||||
public void awaitMessage(TextMessage expected, long timeToWait) throws InterruptedException {
|
||||
TextMessage actual = this.receivedMessages.poll(timeToWait, TimeUnit.MILLISECONDS);
|
||||
assertNotNull("Timed out waiting for [" + expected + "]", actual);
|
||||
assertEquals(expected, actual);
|
||||
if (actual != null) {
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
else if (this.transportError != null) {
|
||||
throw new AssertionError("Transport error", this.transportError);
|
||||
}
|
||||
else {
|
||||
fail("Timed out waiting for [" + expected + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public CloseStatus awaitCloseStatus(long timeToWait) throws InterruptedException {
|
||||
awaitEvent(() -> this.closeStatus != null, timeToWait, " CloseStatus");
|
||||
awaitEvent(() -> this.closeStatus != null || this.transportError != null, timeToWait, " CloseStatus");
|
||||
if (this.transportError != null) {
|
||||
throw new AssertionError("Transport error", this.transportError);
|
||||
}
|
||||
return this.closeStatus;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue