This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 5723995493 Fix unreliable test
5723995493 is described below

commit 5723995493acd416335f236853d9d2286c13ad23
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Sep 30 14:33:43 2025 +0100

    Fix unreliable test
    
    Refactor test so each test uses a dedicated Listener instance
---
 test/org/apache/coyote/http2/TestAsyncError.java | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/test/org/apache/coyote/http2/TestAsyncError.java 
b/test/org/apache/coyote/http2/TestAsyncError.java
index 7a282c0096..1e1ab6b3d0 100644
--- a/test/org/apache/coyote/http2/TestAsyncError.java
+++ b/test/org/apache/coyote/http2/TestAsyncError.java
@@ -49,10 +49,12 @@ public class TestAsyncError extends Http2TestBase {
 
         Tomcat tomcat = getTomcatInstance();
 
+        AsyncErrorServlet asyncErrorServlet = new AsyncErrorServlet();
+
         Context ctxt = getProgrammaticRootContext();
         Tomcat.addServlet(ctxt, "simple", new SimpleServlet());
         ctxt.addServletMappingDecoded("/simple", "simple");
-        Wrapper w = Tomcat.addServlet(ctxt, "async", new AsyncErrorServlet());
+        Wrapper w = Tomcat.addServlet(ctxt, "async", asyncErrorServlet);
         w.setAsyncSupported(true);
         ctxt.addServletMappingDecoded("/async", "async");
         tomcat.start();
@@ -81,12 +83,12 @@ public class TestAsyncError extends Http2TestBase {
         sendRst(3, Http2Error.CANCEL.getCode());
 
         int count = 0;
-        while (count < 50 && TestListener.getErrorCount() == 0) {
+        while (count < 50 && asyncErrorServlet.getErrorCount() == 0) {
             count++;
             Thread.sleep(100);
         }
 
-        Assert.assertEquals(1, TestListener.getErrorCount());
+        Assert.assertEquals(1, asyncErrorServlet.getErrorCount());
     }
 
 
@@ -94,11 +96,16 @@ public class TestAsyncError extends Http2TestBase {
 
         private static final long serialVersionUID = 1L;
 
+        private TestListener testListener = new TestListener();
+
+        int getErrorCount() {
+            return testListener.getErrorCount();
+        }
+
         @Override
         protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
 
             final AsyncContext asyncContext = req.startAsync();
-            TestListener testListener = new TestListener();
             asyncContext.addListener(testListener);
 
             MessageGenerator msgGenerator = new MessageGenerator(resp);
@@ -139,9 +146,9 @@ public class TestAsyncError extends Http2TestBase {
 
     private static final class TestListener implements AsyncListener {
 
-        private static final AtomicInteger errorCount = new AtomicInteger(0);
+        private final AtomicInteger errorCount = new AtomicInteger(0);
 
-        public static int getErrorCount() {
+        public int getErrorCount() {
             return errorCount.get();
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to