Fixed test.
This commit is contained in:
parent
d9255d02d8
commit
6ad90c259c
|
@ -19,15 +19,11 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.http2.client;
|
package org.eclipse.jetty.http2.client;
|
||||||
|
|
||||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -50,6 +46,9 @@ import org.eclipse.jetty.util.Promise;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
public class IdleTimeoutTest extends AbstractTest
|
public class IdleTimeoutTest extends AbstractTest
|
||||||
{
|
{
|
||||||
private final int idleTimeout = 1000;
|
private final int idleTimeout = 1000;
|
||||||
|
@ -95,7 +94,7 @@ public class IdleTimeoutTest extends AbstractTest
|
||||||
|
|
||||||
Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
|
Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
|
||||||
|
|
||||||
Thread.sleep(1000);
|
sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -146,21 +145,16 @@ public class IdleTimeoutTest extends AbstractTest
|
||||||
@Override
|
@Override
|
||||||
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
|
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
|
||||||
{
|
{
|
||||||
try
|
stream.setIdleTimeout(10 * idleTimeout);
|
||||||
{
|
// Stay in the callback for more than idleTimeout,
|
||||||
stream.setIdleTimeout(10 * idleTimeout);
|
// but not for an integer number of idle timeouts,
|
||||||
// Stay in the callback for more than the idleTimeout.
|
// to avoid a race where the idle timeout fires
|
||||||
Thread.sleep(2 * idleTimeout);
|
// again before we can send the headers to the client.
|
||||||
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
|
sleep(idleTimeout + idleTimeout / 2);
|
||||||
HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true);
|
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
|
||||||
stream.headers(responseFrame, Callback.Adapter.INSTANCE);
|
HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true);
|
||||||
return null;
|
stream.headers(responseFrame, Callback.Adapter.INSTANCE);
|
||||||
}
|
return null;
|
||||||
catch (InterruptedException x)
|
|
||||||
{
|
|
||||||
Assert.fail();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connector.setIdleTimeout(idleTimeout);
|
connector.setIdleTimeout(idleTimeout);
|
||||||
|
@ -319,16 +313,11 @@ public class IdleTimeoutTest extends AbstractTest
|
||||||
@Override
|
@Override
|
||||||
public void onHeaders(Stream stream, HeadersFrame frame)
|
public void onHeaders(Stream stream, HeadersFrame frame)
|
||||||
{
|
{
|
||||||
try
|
// Stay in the callback for more than idleTimeout,
|
||||||
{
|
// but not for an integer number of idle timeouts,
|
||||||
// Stay in the callback for more than idleTimeout.
|
// to avoid that the idle timeout fires again.
|
||||||
Thread.sleep(2 * idleTimeout);
|
sleep(idleTimeout + idleTimeout / 2);
|
||||||
replyLatch.countDown();
|
replyLatch.countDown();
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
Assert.fail();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -345,14 +334,7 @@ public class IdleTimeoutTest extends AbstractTest
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
try
|
sleep(2 * idleTimeout);
|
||||||
{
|
|
||||||
Thread.sleep(2 * idleTimeout);
|
|
||||||
}
|
|
||||||
catch (InterruptedException x)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(x);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue