Attempting to understand windows timeout hang

This commit is contained in:
Joakim Erdfelt 2014-11-05 14:39:12 -07:00
parent 67de171871
commit f2cbde13e2
2 changed files with 26 additions and 22 deletions

View File

@ -34,13 +34,18 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.toolchain.test.TestTracker;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
public abstract class ConnectorTimeoutTest extends HttpServerTestFixture public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{ {
@Rule
public TestTracker tracker = new TestTracker();
protected static final int MAX_IDLE_TIME=500; protected static final int MAX_IDLE_TIME=500;
private int sleepTime = MAX_IDLE_TIME + MAX_IDLE_TIME/5; private int sleepTime = MAX_IDLE_TIME + MAX_IDLE_TIME/5;
private int minimumTestRuntime = MAX_IDLE_TIME-MAX_IDLE_TIME/5; private int minimumTestRuntime = MAX_IDLE_TIME-MAX_IDLE_TIME/5;
@ -52,7 +57,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithRequest10() throws Exception public void testMaxIdleWithRequest10() throws Exception
{ {
configureServer(new HelloWorldHandler()); configureServer(new HelloWorldHandler());
@ -82,7 +87,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime); Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime);
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithRequest11() throws Exception public void testMaxIdleWithRequest11() throws Exception
{ {
configureServer(new EchoHandler()); configureServer(new EchoHandler());
@ -115,7 +120,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime); Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime);
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithRequest10NoClientClose() throws Exception public void testMaxIdleWithRequest10NoClientClose() throws Exception
{ {
final Exchanger<EndPoint> exchanger = new Exchanger<>(); final Exchanger<EndPoint> exchanger = new Exchanger<>();
@ -189,7 +194,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
Assert.assertFalse(endPoint.isOpen()); Assert.assertFalse(endPoint.isOpen());
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithRequest10ClientIgnoresClose() throws Exception public void testMaxIdleWithRequest10ClientIgnoresClose() throws Exception
{ {
final Exchanger<EndPoint> exchanger = new Exchanger<>(); final Exchanger<EndPoint> exchanger = new Exchanger<>();
@ -265,7 +270,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
Assert.assertFalse(endPoint.isOpen()); Assert.assertFalse(endPoint.isOpen());
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithRequest11NoClientClose() throws Exception public void testMaxIdleWithRequest11NoClientClose() throws Exception
{ {
final Exchanger<EndPoint> exchanger = new Exchanger<>(); final Exchanger<EndPoint> exchanger = new Exchanger<>();
@ -342,7 +347,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
Assert.assertFalse(endPoint.isOpen()); Assert.assertFalse(endPoint.isOpen());
} }
@Test @Test(timeout=60000)
public void testMaxIdleNoRequest() throws Exception public void testMaxIdleNoRequest() throws Exception
{ {
configureServer(new EchoHandler()); configureServer(new EchoHandler());
@ -370,7 +375,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithSlowRequest() throws Exception public void testMaxIdleWithSlowRequest() throws Exception
{ {
configureServer(new EchoHandler()); configureServer(new EchoHandler());
@ -410,7 +415,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
} }
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithSlowResponse() throws Exception public void testMaxIdleWithSlowResponse() throws Exception
{ {
configureServer(new SlowResponseHandler()); configureServer(new SlowResponseHandler());
@ -439,7 +444,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
} }
} }
@Test @Test(timeout=60000)
public void testMaxIdleWithWait() throws Exception public void testMaxIdleWithWait() throws Exception
{ {
configureServer(new WaitHandler()); configureServer(new WaitHandler());

View File

@ -36,9 +36,6 @@ import org.junit.Test;
public class SelectChannelTimeoutTest extends ConnectorTimeoutTest public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
{ {
@Rule
public TestTracker tracker = new TestTracker();
@Before @Before
public void init() throws Exception public void init() throws Exception
{ {
@ -105,15 +102,17 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
private String getResponse(String request) throws UnsupportedEncodingException, IOException, InterruptedException private String getResponse(String request) throws UnsupportedEncodingException, IOException, InterruptedException
{ {
ServerConnector connector = (ServerConnector)_connector; ServerConnector connector = (ServerConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort());
socket.setSoTimeout(10 * MAX_IDLE_TIME);
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
InputStream inputStream = socket.getInputStream();
long start = System.currentTimeMillis();
String response = IO.toString(inputStream);
long timeElapsed = System.currentTimeMillis() - start;
assertTrue("Time elapsed should be at least MAX_IDLE_TIME",timeElapsed > MAX_IDLE_TIME);
return response;
}
try (Socket socket = new Socket((String)null,connector.getLocalPort()))
{
socket.setSoTimeout(10 * MAX_IDLE_TIME);
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
InputStream inputStream = socket.getInputStream();
long start = System.currentTimeMillis();
String response = IO.toString(inputStream);
long timeElapsed = System.currentTimeMillis() - start;
assertTrue("Time elapsed should be at least MAX_IDLE_TIME",timeElapsed > MAX_IDLE_TIME);
return response;
}
}
} }