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

jvanderzee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ee224f47e Remove duplicate setup in http3 tests (#11608)
9ee224f47e is described below

commit 9ee224f47ec86f9311f2f6b9200967ffceff185b
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.
---
 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 fd38ca8042..bdda7cb2f1 100644
--- a/src/proxy/http3/test/test_Http3FrameDispatcher.cc
+++ b/src/proxy/http3/test/test_Http3FrameDispatcher.cc
@@ -66,6 +66,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[] = {
@@ -87,18 +99,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
@@ -110,7 +110,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")
@@ -129,18 +128,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
@@ -152,7 +139,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")
@@ -169,18 +155,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
@@ -192,7 +166,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")
@@ -209,18 +182,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
@@ -232,7 +193,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")
@@ -249,18 +209,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
@@ -272,8 +220,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);
 }
 
 TEST_CASE("ignore unknown frames", "[http3]")

Reply via email to