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

cmcfarlen pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit f0ab66921bda739e277d79647dd42dd488122dce
Author: JosiahWI <[email protected]>
AuthorDate: Wed Jul 24 12:06:33 2024 -0500

    Remove duplicate setup in http3 tests (#11608)
    
    There was a lot of unnecessary duplication. As more tests are added the 
current
    pattern will worsen if not remediated.
    
    (cherry picked from commit 9ee224f47ec86f9311f2f6b9200967ffceff185b)
---
 src/proxy/http3/test/test_Http3FrameDispatcher.cc | 79 ++++-------------------
 1 file changed, 14 insertions(+), 65 deletions(-)

diff --git a/src/proxy/http3/test/test_Http3FrameDispatcher.cc 
b/src/proxy/http3/test/test_Http3FrameDispatcher.cc
index fc7711f7cc..e81175efe1 100644
--- a/src/proxy/http3/test/test_Http3FrameDispatcher.cc
+++ b/src/proxy/http3/test/test_Http3FrameDispatcher.cc
@@ -102,6 +102,18 @@ TEST_CASE("Http3FrameHandler dispatch", "[http3]")
 
 TEST_CASE("control stream tests", "[http3]")
 {
+  Http3FrameDispatcher  http3FrameDispatcher;
+  Http3ProtocolEnforcer enforcer;
+  Http3MockFrameHandler handler;
+
+  http3FrameDispatcher.add_handler(&enforcer);
+  http3FrameDispatcher.add_handler(&handler);
+
+  MIOBuffer      *buf    = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
+  IOBufferReader *reader = buf->alloc_reader();
+  uint64_t        nread  = 0;
+  Http3ErrorUPtr  error  = Http3ErrorUPtr(nullptr);
+
   SECTION("Only one SETTINGS frame is allowed per the control stream")
   {
     uint8_t input[] = {
@@ -123,18 +135,6 @@ TEST_CASE("control stream tests", "[http3]")
       0x00,       // Value
     };
 
-    Http3FrameDispatcher  http3FrameDispatcher;
-    Http3ProtocolEnforcer enforcer;
-    Http3MockFrameHandler handler;
-
-    http3FrameDispatcher.add_handler(&enforcer);
-    http3FrameDispatcher.add_handler(&handler);
-
-    MIOBuffer      *buf    = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
-    IOBufferReader *reader = buf->alloc_reader();
-    uint64_t        nread  = 0;
-    Http3ErrorUPtr  error  = Http3ErrorUPtr(nullptr);
-
     buf->write(input, sizeof(input));
 
     // Initial state
@@ -146,7 +146,6 @@ TEST_CASE("control stream tests", "[http3]")
     CHECK(error->code == Http3ErrorCode::H3_FRAME_UNEXPECTED);
     CHECK(handler.total_frame_received == 1);
     CHECK(nread == sizeof(input));
-    free_MIOBuffer(buf);
   }
 
   SECTION("first frame of the control stream must be SETTINGS frame")
@@ -165,18 +164,6 @@ TEST_CASE("control stream tests", "[http3]")
       0x00,       // Value
     };
 
-    Http3FrameDispatcher  http3FrameDispatcher;
-    Http3ProtocolEnforcer enforcer;
-    Http3MockFrameHandler handler;
-
-    http3FrameDispatcher.add_handler(&enforcer);
-    http3FrameDispatcher.add_handler(&handler);
-
-    MIOBuffer      *buf    = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
-    IOBufferReader *reader = buf->alloc_reader();
-    uint64_t        nread  = 0;
-    Http3ErrorUPtr  error  = Http3ErrorUPtr(nullptr);
-
     buf->write(input, sizeof(input));
 
     // Initial state
@@ -188,7 +175,6 @@ TEST_CASE("control stream tests", "[http3]")
     CHECK(error->code == Http3ErrorCode::H3_MISSING_SETTINGS);
     CHECK(handler.total_frame_received == 0);
     CHECK(nread == 3);
-    free_MIOBuffer(buf);
   }
 
   SECTION("DATA frame is not allowed on control stream")
@@ -205,18 +191,6 @@ TEST_CASE("control stream tests", "[http3]")
                        0x04,       // Length
                        0x11, 0x22, 0x33, 0x44};
 
-    Http3FrameDispatcher  http3FrameDispatcher;
-    Http3ProtocolEnforcer enforcer;
-    Http3MockFrameHandler handler;
-
-    http3FrameDispatcher.add_handler(&enforcer);
-    http3FrameDispatcher.add_handler(&handler);
-
-    MIOBuffer      *buf    = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
-    IOBufferReader *reader = buf->alloc_reader();
-    uint64_t        nread  = 0;
-    Http3ErrorUPtr  error  = Http3ErrorUPtr(nullptr);
-
     buf->write(input, sizeof(input));
 
     // Initial state
@@ -228,7 +202,6 @@ TEST_CASE("control stream tests", "[http3]")
     CHECK(error->code == Http3ErrorCode::H3_FRAME_UNEXPECTED);
     CHECK(handler.total_frame_received == 1);
     CHECK(nread == sizeof(input));
-    free_MIOBuffer(buf);
   }
 
   SECTION("HEADERS frame is not allowed on control stream")
@@ -245,18 +218,6 @@ TEST_CASE("control stream tests", "[http3]")
                        0x04,       // Length
                        0x11, 0x22, 0x33, 0x44};
 
-    Http3FrameDispatcher  http3FrameDispatcher;
-    Http3ProtocolEnforcer enforcer;
-    Http3MockFrameHandler handler;
-
-    http3FrameDispatcher.add_handler(&enforcer);
-    http3FrameDispatcher.add_handler(&handler);
-
-    MIOBuffer      *buf    = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
-    IOBufferReader *reader = buf->alloc_reader();
-    uint64_t        nread  = 0;
-    Http3ErrorUPtr  error  = Http3ErrorUPtr(nullptr);
-
     buf->write(input, sizeof(input));
 
     // Initial state
@@ -268,7 +229,6 @@ TEST_CASE("control stream tests", "[http3]")
     CHECK(error->code == Http3ErrorCode::H3_FRAME_UNEXPECTED);
     CHECK(handler.total_frame_received == 1);
     CHECK(nread == sizeof(input));
-    free_MIOBuffer(buf);
   }
 
   SECTION("RESERVED frame is not allowed on control stream")
@@ -285,18 +245,6 @@ TEST_CASE("control stream tests", "[http3]")
                        0x04,       // Length
                        0x11, 0x22, 0x33, 0x44};
 
-    Http3FrameDispatcher  http3FrameDispatcher;
-    Http3ProtocolEnforcer enforcer;
-    Http3MockFrameHandler handler;
-
-    http3FrameDispatcher.add_handler(&enforcer);
-    http3FrameDispatcher.add_handler(&handler);
-
-    MIOBuffer      *buf    = new_MIOBuffer(BUFFER_SIZE_INDEX_512);
-    IOBufferReader *reader = buf->alloc_reader();
-    uint64_t        nread  = 0;
-    Http3ErrorUPtr  error  = Http3ErrorUPtr(nullptr);
-
     buf->write(input, sizeof(input));
 
     // Initial state
@@ -308,8 +256,9 @@ TEST_CASE("control stream tests", "[http3]")
     CHECK(error->code == Http3ErrorCode::H3_FRAME_UNEXPECTED);
     CHECK(handler.total_frame_received == 1);
     CHECK(nread == sizeof(input));
-    free_MIOBuffer(buf);
   }
+
+  free_MIOBuffer(buf);
 }
 
 // This test needs to run without an enforcer due to a frame counting bug.

Reply via email to