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 39c855d642 Test that a flush failure does not prevent a dispatch from 
being completed
39c855d642 is described below

commit 39c855d642c2dde64aa9723d737177606bbcc9ec
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Dec 2 16:16:54 2026 +0000

    Test that a flush failure does not prevent a dispatch from being completed
    
    The existing test of a failure to flush buffered output when asynchronous
    processing completes only covered the completing states. Add tests for the 
other
    two states that flush before onComplete() is called and the in-progress 
async
    count is decremented: a dispatch that can no longer be performed 
(MUST_DISPATCH)
    and a dispatch from a non-container thread (DISPATCHING).
    
    Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
 .../coyote/TestAsyncStateMachineFlushFailure.java  | 47 +++++++++++++++++++++-
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/test/org/apache/coyote/TestAsyncStateMachineFlushFailure.java 
b/test/org/apache/coyote/TestAsyncStateMachineFlushFailure.java
index a5320ce2e2..23108949f0 100644
--- a/test/org/apache/coyote/TestAsyncStateMachineFlushFailure.java
+++ b/test/org/apache/coyote/TestAsyncStateMachineFlushFailure.java
@@ -26,8 +26,9 @@ import org.apache.coyote.http11.Http11NioProtocol;
 import org.apache.coyote.http11.Http11Processor;
 
 /**
- * Tests that a failure to flush buffered output when asynchronous processing 
completes, for example because the client
- * has reset the stream, does not prevent the request from being completed.
+ * Tests that a failure to flush buffered output when asynchronous processing 
completes, or when a dispatch that can no
+ * longer be performed is completed, for example because the client has reset 
the stream, does not prevent the request
+ * from being completed.
  */
 public class TestAsyncStateMachineFlushFailure {
 
@@ -50,6 +51,48 @@ public class TestAsyncStateMachineFlushFailure {
     }
 
 
+    @Test
+    public void testFlushFailureWhenDispatchCannotBePerformed() {
+        TestProcessor processor = new TestProcessor();
+        TestAsyncContextCallback asyncCtxt = new TestAsyncContextCallback();
+
+        processor.action(ActionCode.ASYNC_START, asyncCtxt);
+        // A dispatch requested on the container thread while the request is 
starting
+        processor.getRequest().setRequestThread();
+        processor.action(ActionCode.ASYNC_DISPATCH, null);
+        // The connection will be closed but the response can still be 
completed
+        processor.setErrorState(ErrorState.CLOSE_CLEAN, null);
+
+        // Flushing the buffered output fails
+        processor.action(ActionCode.ASYNC_POST_PROCESS, null);
+
+        Assert.assertEquals("The flush should have been attempted", 1, 
processor.flushAttempts.get());
+        Assert.assertEquals("onComplete() must still be fired", 1, 
asyncCtxt.completes.get());
+        Assert.assertEquals("The in-progress async count must still be 
decremented", 1, asyncCtxt.decrements.get());
+        Assert.assertTrue("The failure must still be handled", 
processor.getErrorState().isError());
+    }
+
+
+    @Test
+    public void testFlushFailureWhenDispatching() {
+        TestProcessor processor = new TestProcessor();
+        TestAsyncContextCallback asyncCtxt = new TestAsyncContextCallback();
+
+        processor.action(ActionCode.ASYNC_START, asyncCtxt);
+        processor.action(ActionCode.ASYNC_POST_PROCESS, null);
+        // A dispatch requested from a non-container thread
+        processor.action(ActionCode.ASYNC_DISPATCH, null);
+
+        // Flushing the buffered output fails
+        processor.action(ActionCode.ASYNC_POST_PROCESS, null);
+
+        Assert.assertEquals("The flush should have been attempted", 1, 
processor.flushAttempts.get());
+        Assert.assertEquals("onComplete() must still be fired", 1, 
asyncCtxt.completes.get());
+        Assert.assertEquals("The in-progress async count must still be 
decremented", 1, asyncCtxt.decrements.get());
+        Assert.assertTrue("The failure must still be handled", 
processor.getErrorState().isError());
+    }
+
+
     private static class TestProcessor extends Http11Processor {
 
         private final AtomicInteger flushAttempts = new AtomicInteger();


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

Reply via email to