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

commit f65825a77fdbcc225c895c43c371674ae87c3b79
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Mar 15 19:24:08 2021 +0000

    Fix failing test after flow control updates
---
 .../apache/coyote/http2/TestCancelledUpload.java   | 73 ++++++++--------------
 1 file changed, 26 insertions(+), 47 deletions(-)

diff --git a/test/org/apache/coyote/http2/TestCancelledUpload.java 
b/test/org/apache/coyote/http2/TestCancelledUpload.java
index 9964aa4..accd4b3 100644
--- a/test/org/apache/coyote/http2/TestCancelledUpload.java
+++ b/test/org/apache/coyote/http2/TestCancelledUpload.java
@@ -73,26 +73,6 @@ public class TestCancelledUpload extends Http2TestBase {
         // - reset the stream if further DATA frames are received
         parser.readFrame(true);
 
-        // If reset is first frame received end test here
-        if (checkReset()) {
-            return;
-        }
-
-        // Validate any WindowSize frames. Usually arrive in pairs. Depending 
on
-        // timing, can see a reset rather than than stream update.
-        while (output.getTrace().startsWith("0-WindowSize-[")) {
-            String trace = output.getTrace();
-            int size = Integer.parseInt(trace.substring(14, trace.length() - 
2));
-            output.clearTrace();
-            parser.readFrame(true);
-            if (checkReset()) {
-                return;
-            }
-            Assert.assertEquals("3-WindowSize-[" + size + "]\n", 
output.getTrace());
-            output.clearTrace();
-            parser.readFrame(true);
-        }
-
         // Check for reset and exit if found
         if (checkReset()) {
             return;
@@ -106,58 +86,57 @@ public class TestCancelledUpload extends Http2TestBase {
                 "3-HeadersEnd\n",
                 output.getTrace());
         output.clearTrace();
-
         parser.readFrame(true);
+
         // Check for reset and exit if found
         if (checkReset()) {
             return;
         }
 
-        // Not reset, must be request body
+        // Not window update, not reset, must be the response body
         Assert.assertEquals("3-Body-0\n" +
                 "3-EndOfStream\n",
                 output.getTrace());
         output.clearTrace();
-
-        // There must be a reset. There may be some WindowSize frames
         parser.readFrame(true);
 
-        // Validate any WindowSize frames. Usually arrive in pairs. Depending 
on
-        // timing, can see a reset rather than than stream update.
-        while (output.getTrace().startsWith("0-WindowSize-[")) {
-            String trace = output.getTrace();
-            int size = Integer.parseInt(trace.substring(14, trace.length() - 
2));
-            output.clearTrace();
-            parser.readFrame(true);
-            if (checkReset()) {
-                return;
-            }
-            Assert.assertEquals("3-WindowSize-[" + size + "]\n", 
output.getTrace());
-            output.clearTrace();
-            parser.readFrame(true);
-        }
-
-        // This should be the reset
-        checkReset();
-        Assert.assertEquals("3-RST-[3]\n", output.getTrace());
+        Assert.assertTrue(checkReset());
 
         // If there are any more frames after this, ignore them
     }
 
 
     /*
-     * Depending on timing, several resets may be sent.
+     * Looking for a RST frame with error type 3 (flow control error).
+     *
+     * If there is a flow control window update for stream 0 it may be followed
+     * by one for stream 3.
+     *
+     * If there is a flow control window update for stream 3 it will always be
+     * preceded by one for stream 0.
      */
     private boolean checkReset() throws IOException, Http2Exception {
+        int lastConnectionFlowControlWindowUpdate = -1;
         while (true) {
-            if (output.getTrace().startsWith("3-RST-[3]\n")) {
+            String trace = output.getTrace();
+            if (trace.startsWith("3-RST-[3]\n")) {
+                // This is the reset we are looking for
                 return true;
-            } else if (output.getTrace().startsWith("3-RST-[")) {
-                output.clearTrace();
-                parser.readFrame(true);
+            } else if (trace.startsWith("3-RST-[")) {
+                // Probably error type 8 (cancel) - ignore
+            } else if (trace.startsWith("0-WindowSize-[")) {
+                // Connection flow control window update
+                lastConnectionFlowControlWindowUpdate = 
Integer.parseInt(trace.substring(14, trace.length() - 2));
+            } else if (trace.startsWith("3-WindowSize-[")) {
+                // Stream flow control window update
+                // Must be same size as last connection flow control window
+                // update. True for Tomcat anyway.
+                Assert.assertEquals("3-WindowSize-[" + 
lastConnectionFlowControlWindowUpdate + "]\n", trace);
             } else {
                 return false;
             }
+            output.clearTrace();
+            parser.readFrame(true);
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to