Enabling more websocket tests
This commit is contained in:
parent
21b1ecef7b
commit
31705767f0
|
@ -179,7 +179,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
|
|||
|
||||
private void close(CloseInfo closeInfo, FrameCallback callback)
|
||||
{
|
||||
connectionState.onClosing(); // move to CLOSING state (always)
|
||||
connectionState.onClosing(); // always move to (at least) the CLOSING state (might already be past it, which is ok)
|
||||
|
||||
if (closeSent.compareAndSet(false, true))
|
||||
{
|
||||
|
@ -192,7 +192,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
|
|||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Close Frame Previously Sent: ignoring: {} [{}]", closeInfo, callback);
|
||||
callback.succeed();
|
||||
callback.fail(new WebSocketException("Already closed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public abstract class AbstractTrackingEndpoint<T>
|
|||
public CountDownLatch closeLatch = new CountDownLatch(1);
|
||||
public CountDownLatch errorLatch = new CountDownLatch(1);
|
||||
public AtomicReference<CloseInfo> closeInfo = new AtomicReference<>();
|
||||
public AtomicReference<Throwable> closeStack = new AtomicReference<>();
|
||||
public AtomicReference<Throwable> error = new AtomicReference<>();
|
||||
|
||||
public AbstractTrackingEndpoint(String id)
|
||||
|
@ -114,10 +115,11 @@ public abstract class AbstractTrackingEndpoint<T>
|
|||
CloseInfo close = new CloseInfo(statusCode, reason);
|
||||
if (closeInfo.compareAndSet(null, close) == false)
|
||||
{
|
||||
LOG.warn("onClose should only happen once - Original Close: " + closeInfo.get());
|
||||
LOG.warn("onClose should only happen once - Extra/Excess Close: " + close);
|
||||
LOG.warn("onClose should only happen once - Original Close: " + closeInfo.get(), closeStack.get());
|
||||
LOG.warn("onClose should only happen once - Extra/Excess Close: " + close, new Throwable("extra/excess"));
|
||||
fail("onClose should only happen once!");
|
||||
}
|
||||
closeStack.compareAndSet(null, new Throwable("original"));
|
||||
this.closeLatch.countDown();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.tests.client;
|
||||
|
||||
import static org.hamcrest.Matchers.anything;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
@ -26,7 +25,6 @@ import static org.hamcrest.Matchers.nullValue;
|
|||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectableChannel;
|
||||
|
@ -51,7 +49,7 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
|||
import org.eclipse.jetty.websocket.api.BatchMode;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketTimeoutException;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||
|
@ -62,7 +60,6 @@ import org.eclipse.jetty.websocket.tests.UntrustedWSServer;
|
|||
import org.eclipse.jetty.websocket.tests.UntrustedWSSession;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
@ -166,20 +163,6 @@ public class ClientCloseTest
|
|||
public void startServer() throws Exception
|
||||
{
|
||||
server = new UntrustedWSServer();
|
||||
server.registerWebSocket("/noclose", (req, resp) -> new WebSocketAdapter()
|
||||
{
|
||||
@Override
|
||||
public void onWebSocketClose(int statusCode, String reason)
|
||||
{
|
||||
try
|
||||
{
|
||||
getSession().disconnect();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
}
|
||||
}
|
||||
});
|
||||
server.start();
|
||||
}
|
||||
|
||||
|
@ -196,7 +179,6 @@ public class ClientCloseTest
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Not working yet")
|
||||
public void testNetworkCongestion() throws Exception
|
||||
{
|
||||
// Set client timeout
|
||||
|
@ -211,13 +193,12 @@ public class ClientCloseTest
|
|||
TrackingEndpoint clientSocket = new TrackingEndpoint(testname.getMethodName());
|
||||
Future<Session> clientConnectFuture = client.connect(clientSocket, wsUri);
|
||||
|
||||
// Server accepts connect
|
||||
UntrustedWSSession serverSession = serverSessionFut.get(10, TimeUnit.SECONDS);
|
||||
Session clientSession = clientConnectFuture.get(Defaults.CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
// client confirms connection via echo
|
||||
confirmConnection(clientSocket, clientConnectFuture, serverSession);
|
||||
try
|
||||
{
|
||||
|
||||
// client sends BIG frames (until it cannot write anymore)
|
||||
// client sends frames big enough to break through network layer caching, until it cannot write anymore.
|
||||
// server must not read (for test purpose, in order to congest connection)
|
||||
// when write is congested, client enqueue close frame
|
||||
// client initiate write, but write never completes
|
||||
|
@ -241,7 +222,13 @@ public class ClientCloseTest
|
|||
LOG.info("Wrote {} frames totalling {} bytes of payload before congestion kicked in", writeCount, writeSize);
|
||||
|
||||
// Verify timeout error
|
||||
clientSocket.assertErrorEvent("Client", instanceOf(SocketTimeoutException.class), anything());
|
||||
clientSocket.awaitErrorEvent("Client");
|
||||
clientSocket.assertErrorEvent("Client", instanceOf(WebSocketTimeoutException.class), containsString("Idle Timeout"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
clientSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000L)
|
||||
|
|
Loading…
Reference in New Issue