This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new f3d1f8ff68 Reduce test runtime
f3d1f8ff68 is described below
commit f3d1f8ff688edac70f9a4fb28ee0235a88bb05a2
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Oct 20 18:54:44 2026 +0100
Reduce test runtime
Co-authored by: Codex / GPT-6.1-Sol-High
---
.../apache/catalina/core/TestAsyncContextImpl.java | 59 ++++++++++++++--------
1 file changed, 39 insertions(+), 20 deletions(-)
diff --git a/test/org/apache/catalina/core/TestAsyncContextImpl.java
b/test/org/apache/catalina/core/TestAsyncContextImpl.java
index 106f90db68..ebf1a214d6 100644
--- a/test/org/apache/catalina/core/TestAsyncContextImpl.java
+++ b/test/org/apache/catalina/core/TestAsyncContextImpl.java
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.LogManager;
@@ -64,6 +65,7 @@ import org.apache.catalina.startup.SimpleHttpClient;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.catalina.valves.TesterAccessLogValve;
+import org.apache.catalina.valves.ValveBase;
import org.apache.tomcat.unittest.TesterContext;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.EncodedSolidusHandling;
@@ -1003,6 +1005,24 @@ public class TestAsyncContextImpl extends TomcatBaseTest
{
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
+ CountDownLatch initialRequestReturned = new CountDownLatch(1);
+ // Wait for the initial request to leave the host's ErrorReportValve
before triggering the async error.
+ tomcat.getEngine().getPipeline().addValve(new ValveBase(true) {
+ private final AtomicBoolean firstInvocation = new
AtomicBoolean(true);
+
+ @Override
+ public void invoke(Request request, Response response) throws
IOException, ServletException {
+ boolean first = firstInvocation.getAndSet(false);
+ try {
+ getNext().invoke(request, response);
+ } finally {
+ if (first) {
+ initialRequestReturned.countDown();
+ }
+ }
+ }
+ });
+
// No file system docBase required
Context ctx = getProgrammaticRootContext();
@@ -1011,7 +1031,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest {
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/stage1", "dispatch");
- ErrorServlet error = new ErrorServlet();
+ ErrorServlet error = new ErrorServlet(initialRequestReturned);
Tomcat.addServlet(ctx, "error", error);
ctx.addServletMapping("/stage2", "error");
@@ -1061,15 +1081,26 @@ public class TestAsyncContextImpl extends
TomcatBaseTest {
private static final long serialVersionUID = 1L;
+ private final transient CountDownLatch initialRequestReturned;
+
+ ErrorServlet(CountDownLatch initialRequestReturned) {
+ this.initialRequestReturned = initialRequestReturned;
+ }
+
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
track("ErrorServletGet-");
- try {
- // Give the original thread a chance to exit the
- // ErrorReportValve before we throw this exception
- Thread.sleep(500);
- } catch (InterruptedException e) {
- throw new ServletException(e);
+ if (initialRequestReturned != null) {
+ try {
+ if (!initialRequestReturned.await(10, TimeUnit.SECONDS)) {
+ track("InitialRequestDidNotReturn-");
+ throw new ServletException("Initial request did not
return through the pipeline");
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ track("InitialRequestWaitInterrupted-");
+ throw new ServletException(e);
+ }
}
throw new ServletException("Oops.");
}
@@ -1211,7 +1242,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest {
// No file system docBase required
Context ctx = getProgrammaticRootContext();
- ErrorServlet error = new ErrorServlet();
+ ErrorServlet error = new ErrorServlet(null);
Tomcat.addServlet(ctx, "error", error);
ctx.addServletMapping("/error", "error");
@@ -1229,10 +1260,6 @@ public class TestAsyncContextImpl extends TomcatBaseTest
{
Assert.assertEquals(500, rc);
- // Without this test may complete before access log has a chance to log
- // the request
- Thread.sleep(REQUEST_TIME);
-
// Check the access log
alv.validateAccessLog(1, 500, 0, REQUEST_TIME);
}
@@ -1264,10 +1291,6 @@ public class TestAsyncContextImpl extends TomcatBaseTest
{
Assert.assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);
- // Without this test may complete before access log has a chance to log
- // the request
- Thread.sleep(REQUEST_TIME);
-
// Check the access log
alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0,
REQUEST_TIME);
@@ -1363,10 +1386,6 @@ public class TestAsyncContextImpl extends TomcatBaseTest
{
Assert.assertTrue(responseBody,
responseBody.contains(AsyncErrorServlet.ERROR_MESSAGE));
}
- // Without this test may complete before access log has a chance to log
- // the request
- Thread.sleep(REQUEST_TIME);
-
// Check the access log
alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0,
REQUEST_TIME);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]