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