diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxy.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxy.java index 03861b98b0f..abaa272ecb0 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxy.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxy.java @@ -176,7 +176,7 @@ public class WebSocketProxy { // If we have sent out a ping then we have already responded with automatic pong. // If this is an unsolicited pong we still need to forward it to the server. - int valueBeforeUpdate = pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i); + int valueBeforeUpdate = proxyToServer.pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i); if (valueBeforeUpdate == 0) proxyToServer.getSession().getRemote().sendPong(BufferUtil.copy(payload)); } @@ -297,7 +297,7 @@ public class WebSocketProxy { // If we have sent out a ping then we have already responded with automatic pong. // If this is an unsolicited pong we still need to forward it to the client. - int valueBeforeUpdate = pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i); + int valueBeforeUpdate = clientToProxy.pingsReceived.getAndUpdate(i -> i > 0 ? i - 1 : i); if (valueBeforeUpdate == 0) clientToProxy.getSession().getRemote().sendPong(BufferUtil.copy(payload)); } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxyTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxyTest.java index e13605cbc9a..59b848c7f4c 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxyTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/proxy/WebSocketProxyTest.java @@ -283,21 +283,21 @@ public class WebSocketProxyTest assertThat(clientSocket.pongMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer("unsolicited pong from server"))); // Test pings from client. - for (int i = 0; i < 10; i++) - clientSocket.session.getRemote().sendPing(BufferUtil.toBuffer(i)); - for (int i = 0; i < 10; i++) + for (int i = 0; i < 15; i++) + clientSocket.session.getRemote().sendPing(intToStringByteBuffer(i)); + for (int i = 0; i < 15; i++) { - assertThat(serverEndpoint.pingMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i))); - assertThat(clientSocket.pongMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i))); + assertThat(serverEndpoint.pingMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i))); + assertThat(clientSocket.pongMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i))); } // Test pings from server. - for (int i = 0; i < 10; i++) - serverEndpoint.session.getRemote().sendPing(BufferUtil.toBuffer(i)); - for (int i = 0; i < 10; i++) + for (int i = 0; i < 23; i++) + serverEndpoint.session.getRemote().sendPing(intToStringByteBuffer(i)); + for (int i = 0; i < 23; i++) { - assertThat(clientSocket.pingMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i))); - assertThat(serverEndpoint.pongMessages.poll(5, TimeUnit.SECONDS), is(BufferUtil.toBuffer(i))); + assertThat(clientSocket.pingMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i))); + assertThat(serverEndpoint.pongMessages.poll(5, TimeUnit.SECONDS), is(intToStringByteBuffer(i))); } clientSocket.session.close(StatusCode.NORMAL, "closing from test"); @@ -322,6 +322,11 @@ public class WebSocketProxyTest assertThat(serverEndpoint.pingMessages.size(), is(0)); } + private ByteBuffer intToStringByteBuffer(int i) + { + return BufferUtil.toBuffer(Integer.toString(i)); + } + @WebSocket public static class PingPongSocket extends EventSocket {