#6327 rework testRequestIdleTimeout and merge http(s) and fcgi test

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2021-08-05 16:34:00 +02:00
parent c818581185
commit 15bef0c9ed
3 changed files with 54 additions and 84 deletions

View File

@ -40,7 +40,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@ -49,7 +48,6 @@ import java.util.function.LongConsumer;
import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
@ -687,47 +685,6 @@ public class HttpClientTest extends AbstractHttpClientServerTest
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ParameterizedTest
@ArgumentsSource(ScenarioProvider.class)
public void testRequestIdleTimeout(Scenario scenario) throws Exception
{
long idleTimeout = 100;
start(scenario, new AbstractHandler()
{
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws ServletException
{
try
{
baseRequest.setHandled(true);
TimeUnit.MILLISECONDS.sleep(2 * idleTimeout);
}
catch (InterruptedException x)
{
throw new ServletException(x);
}
}
});
String host = "localhost";
int port = connector.getLocalPort();
assertThrows(TimeoutException.class, () ->
client.newRequest(host, port)
.scheme(scenario.getScheme())
.idleTimeout(idleTimeout, TimeUnit.MILLISECONDS)
.timeout(3 * idleTimeout, TimeUnit.MILLISECONDS)
.send());
// Make another request without specifying the idle timeout, should not fail
ContentResponse response = client.newRequest(host, port)
.scheme(scenario.getScheme())
.timeout(3 * idleTimeout, TimeUnit.MILLISECONDS)
.send();
assertNotNull(response);
assertEquals(200, response.getStatus());
}
@ParameterizedTest
@ArgumentsSource(ScenarioProvider.class)
public void testSendToIPv6Address(Scenario scenario) throws Exception

View File

@ -24,7 +24,6 @@ import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.GZIPOutputStream;
@ -409,46 +408,6 @@ public class HttpClientTest extends AbstractHttpClientServerTest
assertArrayEquals(data, response.getContent());
}
@Test
public void testRequestIdleTimeout() throws Exception
{
final long idleTimeout = 1000;
start(new AbstractHandler()
{
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws ServletException
{
try
{
baseRequest.setHandled(true);
TimeUnit.MILLISECONDS.sleep(idleTimeout);
}
catch (InterruptedException x)
{
throw new ServletException(x);
}
}
});
final String host = "localhost";
final int port = connector.getLocalPort();
assertThrows(TimeoutException.class, () ->
client.newRequest(host, port)
.scheme(scheme)
.idleTimeout(idleTimeout * 90 / 100, TimeUnit.MILLISECONDS)
.timeout(3 * idleTimeout, TimeUnit.MILLISECONDS)
.send());
// Make another request without specifying the idle timeout, should not fail
ContentResponse response = client.newRequest(host, port)
.scheme(scheme)
.timeout(3 * idleTimeout, TimeUnit.MILLISECONDS)
.send();
assertNotNull(response);
assertEquals(200, response.getStatus());
}
@Test
public void testConnectionIdleTimeout() throws Exception
{

View File

@ -22,9 +22,11 @@ import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.IntStream;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
@ -781,6 +783,58 @@ public class HttpClientTest extends AbstractTest<TransportScenario>
assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
@ParameterizedTest
@ArgumentsSource(TransportProvider.class)
public void testRequestIdleTimeout(Transport transport) throws Exception
{
init(transport);
CountDownLatch latch = new CountDownLatch(1);
long idleTimeout = 500;
scenario.start(new AbstractHandler()
{
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws ServletException
{
try
{
baseRequest.setHandled(true);
if (target.equals("/1"))
assertTrue(latch.await(5, TimeUnit.SECONDS));
else if (target.equals("/2"))
Thread.sleep(2 * idleTimeout);
else
fail("Unknown path: " + target);
}
catch (InterruptedException x)
{
throw new ServletException(x);
}
}
});
String host = "localhost";
int port = scenario.getNetworkConnectorLocalPortInt().get();
assertThrows(TimeoutException.class, () ->
scenario.client.newRequest(host, port)
.scheme(scenario.getScheme())
.path("/1")
.idleTimeout(idleTimeout, TimeUnit.MILLISECONDS)
.timeout(2 * idleTimeout, TimeUnit.MILLISECONDS)
.send());
latch.countDown();
// Make another request without specifying the idle timeout, should not fail
ContentResponse response = scenario.client.newRequest(host, port)
.scheme(scenario.getScheme())
.path("/2")
.timeout(3 * idleTimeout, TimeUnit.MILLISECONDS)
.send();
assertNotNull(response);
assertEquals(200, response.getStatus());
}
private void sleep(long time) throws IOException
{
try