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 8485602258 Fix race in AsyncContext dispatch failure tests
8485602258 is described below

commit 8485602258219665cce278e302f9de205f434836
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Nov 30 11:48:39 2026 +0000

    Fix race in AsyncContext dispatch failure tests
    
    The client can receive the response before the container thread calls
    AsyncListener.onError(). Wait for onComplete(), which is called after
    onError(), before checking what the listeners received. Without this,
    testAsyncDispatchNoArgFailureNonContainerThread can fail intermittently
    and the second listener test can pass without the listener having run.
    
    Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
 test/org/apache/catalina/core/TestAsyncContextImpl.java | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/test/org/apache/catalina/core/TestAsyncContextImpl.java 
b/test/org/apache/catalina/core/TestAsyncContextImpl.java
index 2bcc6d6969..3dd3d15c4c 100644
--- a/test/org/apache/catalina/core/TestAsyncContextImpl.java
+++ b/test/org/apache/catalina/core/TestAsyncContextImpl.java
@@ -2600,13 +2600,17 @@ public class TestAsyncContextImpl extends 
TomcatBaseTest {
         Assert.assertTrue("Request waited for the async timeout: " + elapsed + 
"ms", elapsed < 5000);
         Assert.assertTrue("The caller must be told about the failure", 
servlet.callerException.get() instanceof
                 UnsupportedOperationException);
+        /*
+         * The client can receive the response before the container thread 
calls onError() so wait for onComplete(),
+         * which is called after onError(), before checking what onError() 
received.
+         */
+        Assert.assertTrue("onComplete() must be called", 
servlet.completed.await(5, TimeUnit.SECONDS));
         // The failure is handled like any other failure of an async dispatch 
so may be wrapped
         Throwable listenerThrowable = servlet.listenerThrowable.get();
         while (listenerThrowable != null && !(listenerThrowable instanceof 
UnsupportedOperationException)) {
             listenerThrowable = listenerThrowable.getCause();
         }
         Assert.assertNotNull("onError() must be called with the failure", 
listenerThrowable);
-        Assert.assertTrue("onComplete() must be called", 
servlet.completed.await(5, TimeUnit.SECONDS));
     }
 
 
@@ -2667,9 +2671,13 @@ public class TestAsyncContextImpl extends TomcatBaseTest 
{
         long elapsed = doTestAsyncDispatchNoArgFailure(servlet, null, 
responseBody);
 
         Assert.assertTrue("Request waited for the async timeout: " + elapsed + 
"ms", elapsed < 5000);
+        /*
+         * The client can receive the response before the container thread 
calls the listeners so wait for onComplete(),
+         * which is called after onError(), before checking what the second 
listener's onError() did.
+         */
+        Assert.assertTrue("onComplete() must be called", 
servlet.completed.await(5, TimeUnit.SECONDS));
         Assert.assertNull("The second listener must be able to use the 
AsyncContext",
                 servlet.secondListenerException.get());
-        Assert.assertTrue("onComplete() must be called", 
servlet.completed.await(5, TimeUnit.SECONDS));
     }
 
 


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

Reply via email to