Skip to content

Commit

Permalink
Test Tomcat's handling of a request on an idle connection
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Mar 10, 2020
1 parent b8cb61b commit 19cc388
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.net.SocketException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -57,7 +58,9 @@
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.HttpClients;
import org.apache.jasper.servlet.JspServlet;
import org.apache.tomcat.JarScanFilter;
import org.apache.tomcat.JarScanType;
Expand Down Expand Up @@ -582,8 +585,40 @@ void whenServerIsShuttingDownGracefullyThenNewConnectionsCannotBeMade() throws E
assertThat(shutdownResult.get()).isEqualTo(false);
blockingServlet.admitOne();
assertThat(request.get()).isInstanceOf(HttpResponse.class);
this.webServer.stop();
assertThat(unconnectableRequest.get()).isInstanceOf(HttpHostConnectException.class);
this.webServer.stop();
}

@Test
void whenServerIsShuttingDownARequestOnAnIdleConnectionResultsInConnectionReset() throws Exception {

This comment has been minimized.

Copy link
@dreis2211

dreis2211 Mar 10, 2020

Contributor

This seems to fail on JDK 11+, @wilkinsona . Are you aware?

This comment has been minimized.

Copy link
@wilkinsona

wilkinsona Mar 10, 2020

Author Member

I am. Thanks for making sure though. I'm trying to figure out what's causing the difference and if I can safely change the test's expectation or if there's more to it.

AbstractServletWebServerFactory factory = getFactory();
Shutdown shutdown = new Shutdown();
shutdown.setGracePeriod(Duration.ofSeconds(5));
factory.setShutdown(shutdown);
BlockingServlet blockingServlet = new BlockingServlet();
this.webServer = factory.getWebServer((context) -> {
Dynamic registration = context.addServlet("blockingServlet", blockingServlet);
registration.addMapping("/blocking");
registration.setAsyncSupported(true);
});
HttpClient httpClient = HttpClients.createMinimal();
this.webServer.start();
int port = this.webServer.getPort();
Future<Object> keepAliveRequest = initiateGetRequest(httpClient, port, "/blocking");
blockingServlet.awaitQueue();
blockingServlet.admitOne();
assertThat(keepAliveRequest.get()).isInstanceOf(HttpResponse.class);
Future<Object> request = initiateGetRequest(port, "/blocking");
blockingServlet.awaitQueue();
initiateGracefulShutdown();
Future<Object> idleConnectionRequest = initiateGetRequest(httpClient, port, "/blocking");
blockingServlet.admitOne();
Object response = request.get();
assertThat(response).isInstanceOf(HttpResponse.class);
Object idleConnectionRequestResult = idleConnectionRequest.get();
assertThat(idleConnectionRequestResult).isInstanceOf(SocketException.class);
assertThat((SocketException) idleConnectionRequestResult).hasMessage("Connection reset");
this.webServer.stop();
}

@Override
Expand Down

0 comments on commit 19cc388

Please sign in to comment.