Merge pull request #4087 from eclipse/jetty-9.4.x-3982-WebSocketConnectionStatsTest

Issue #3982 - fix flaky test WebSocketStatsTest
This commit is contained in:
Joakim Erdfelt 2019-09-13 12:19:02 -05:00 committed by GitHub
commit 8cd1759681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 25 deletions

View File

@ -34,7 +34,6 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.CloseInfo;
@ -46,14 +45,13 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class WebSocketConnectionStatsTest
public class WebSocketStatsTest
{
public static class MyWebSocketServlet extends WebSocketServlet
{
@ -121,7 +119,6 @@ public class WebSocketConnectionStatsTest
return buffer.position() - pos;
}
@Disabled("Flaky test see issue #3982")
@Test
public void echoStatsTest() throws Exception
{
@ -145,12 +142,11 @@ public class WebSocketConnectionStatsTest
{
session.getRemote().sendString(msgText);
}
session.close(StatusCode.NORMAL, null);
assertTrue(socket.closed.await(5, TimeUnit.SECONDS));
assertTrue(wsConnectionClosed.await(5, TimeUnit.SECONDS));
}
assertTrue(socket.closed.await(5, TimeUnit.SECONDS));
assertTrue(wsConnectionClosed.await(5, TimeUnit.SECONDS));
assertThat(statistics.getConnectionsMax(), is(1L));
assertThat(statistics.getConnections(), is(0L));
@ -164,12 +160,6 @@ public class WebSocketConnectionStatsTest
final long closeFrameSize = getFrameByteSize(closeFrame);
final int maskSize = 4; // We use 4 byte mask for client frames
// Pointless Sanity Checks
// assertThat("Upgrade Sent Bytes", upgradeSentBytes, is(197L));
// assertThat("Upgrade Received Bytes", upgradeReceivedBytes, is(261L));
// assertThat("Text Frame Size", textFrameSize, is(13L));
// assertThat("Close Frame Size", closeFrameSize, is(4L));
final long expectedSent = upgradeSentBytes + numMessages * textFrameSize + closeFrameSize;
final long expectedReceived = upgradeReceivedBytes + numMessages * (textFrameSize + maskSize) + closeFrameSize + maskSize;

View File

@ -65,7 +65,6 @@ public class Parser
// Stats (where a message is defined as a WebSocket frame)
private final LongAdder messagesIn = new LongAdder();
private final LongAdder bytesIn = new LongAdder();
// State specific
private State state = State.START;
@ -250,8 +249,6 @@ public class Parser
try
{
int startingBytes = buffer.remaining();
// attempt to parse a frame from the buffer
if (parseFrame(buffer))
{
@ -266,8 +263,6 @@ public class Parser
}
reset();
}
bytesIn.add(startingBytes - buffer.remaining());
}
catch (Throwable t)
{
@ -657,11 +652,6 @@ public class Parser
return messagesIn.longValue();
}
public long getBytesIn()
{
return bytesIn.longValue();
}
@Override
public String toString()
{

View File

@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
import org.eclipse.jetty.io.AbstractConnection;
import org.eclipse.jetty.io.AbstractEndPoint;
@ -100,6 +101,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
}
}
@Deprecated
public static class Stats
{
private AtomicLong countFillInterestedEvents = new AtomicLong(0);
@ -139,6 +141,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
private final ConnectionState connectionState = new ConnectionState();
private final FrameFlusher flusher;
private final String id;
private final LongAdder bytesIn = new LongAdder();
private WebSocketSession session;
private List<ExtensionConfig> extensions = new ArrayList<>();
private ByteBuffer prefillBuffer;
@ -400,6 +403,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
return scheduler;
}
@Deprecated()
public Stats getStats()
{
return stats;
@ -472,6 +476,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
return;
}
bytesIn.add(filled);
if (LOG.isDebugEnabled())
LOG.debug("Filled {} bytes - {}", filled, BufferUtil.toDetailString(buffer));
}
@ -668,7 +673,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
@Override
public long getBytesIn()
{
return parser.getBytesIn();
return bytesIn.longValue();
}
/**