Copilot commented on code in PR #12476:
URL: https://github.com/apache/trafficserver/pull/12476#discussion_r2310812075


##########
tests/gold_tests/client_connection/per_client_connection_max.test.py:
##########
@@ -47,26 +48,40 @@ def to_str(cls, protocol: int) -> str:
 class PerClientConnectionMaxTest:
     """Define an object to test our max client connection behavior."""
 
-    _dns_counter: int = 0
-    _server_counter: int = 0
-    _ts_counter: int = 0
-    _client_counter: int = 0
+    _process_counter: int = 0
     _max_client_connections: int = 3
     _protocol_to_replay_file = {
         Protocol.HTTP: 'http_slow_origins.replay.yaml',
         Protocol.HTTPS: 'https_slow_origins.replay.yaml',
         Protocol.HTTP2: 'http2_slow_origins.replay.yaml',
     }
 
-    def __init__(self, protocol: int) -> None:
+    def __init__(self, protocol: int, exempt_list: str = '', exempt_list_file: 
str = '', exempt_list_applies: bool = False) -> None:
         """Configure the test processes in preparation for the TestRun.
 
         :param protocol: The protocol to test.
+        :param exempt_list: A comma-separated string of IP addresses or ranges 
to exempt.
+          The default empty string implies that no exempt list will be 
configured.
+        :param exempt_list_file: A file containing a list of IP addresses or 
ranges to exempt.
+          The default empty string implies that no exempt list will be 
configured.
+        :param exempt_list_applies: If True, the exempt list is assumed to 
exempt
+          the test connections. Thus the per client max connections is expected
+          to be enforced for the connections.

Review Comment:
   The docstring comment on line 68 contains an error. It states that when 
`exempt_list_applies` is True, 'the per client max connections is expected to 
be enforced for the connections.' This should say 'NOT enforced' since exempt 
lists bypass the connection limits.
   ```suggestion
             to NOT be enforced for the connections.
   ```



##########
tests/gold_tests/client_connection/per_client_connection_max.test.py:
##########
@@ -47,26 +48,40 @@ def to_str(cls, protocol: int) -> str:
 class PerClientConnectionMaxTest:
     """Define an object to test our max client connection behavior."""
 
-    _dns_counter: int = 0
-    _server_counter: int = 0
-    _ts_counter: int = 0
-    _client_counter: int = 0
+    _process_counter: int = 0
     _max_client_connections: int = 3
     _protocol_to_replay_file = {
         Protocol.HTTP: 'http_slow_origins.replay.yaml',
         Protocol.HTTPS: 'https_slow_origins.replay.yaml',
         Protocol.HTTP2: 'http2_slow_origins.replay.yaml',
     }
 
-    def __init__(self, protocol: int) -> None:
+    def __init__(self, protocol: int, exempt_list: str = '', exempt_list_file: 
str = '', exempt_list_applies: bool = False) -> None:
         """Configure the test processes in preparation for the TestRun.
 
         :param protocol: The protocol to test.
+        :param exempt_list: A comma-separated string of IP addresses or ranges 
to exempt.
+          The default empty string implies that no exempt list will be 
configured.
+        :param exempt_list_file: A file containing a list of IP addresses or 
ranges to exempt.
+          The default empty string implies that no exempt list will be 
configured.
+        :param exempt_list_applies: If True, the exempt list is assumed to 
exempt
+          the test connections. Thus the per client max connections is expected
+          to be enforced for the connections.
         """
+        self._process_counter = PerClientConnectionMaxTest._process_counter
+        PerClientConnectionMaxTest._process_counter += 1
         self._protocol = protocol
         protocol_string = Protocol.to_str(protocol)
         self._replay_file = self._protocol_to_replay_file[protocol]
-        tr = Test.AddTestRun(f'proxy.config.net.per_client.connection.max: 
{protocol_string}')
+        self._exempt_list = exempt_list
+        self._exempt_list_file = exempt_list_file
+        self._exempt_list_applies = exempt_list_applies
+
+        exempt_list_description = 'exempted' if exempt_list_applies else 'not 
exempted'
+        exempt_description = 'exempt_list' if exempt_list else 
'exempt_list_file'

Review Comment:
   The logic for `exempt_description` is incorrect. When `exempt_list` is empty 
(falsy), it defaults to 'exempt_list_file' even when `exempt_list_file` might 
also be empty. This should check both parameters to determine the appropriate 
description.
   ```suggestion
           if exempt_list and exempt_list_file:
               exempt_description = 'exempt_list_and_file'
           elif exempt_list:
               exempt_description = 'exempt_list'
           elif exempt_list_file:
               exempt_description = 'exempt_list_file'
           else:
               exempt_description = 'no_exempt_list'
   ```



##########
plugins/experimental/connection_exempt_list/connection_exempt_list.cript:
##########
@@ -0,0 +1,86 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+#include <cripts/Preamble.hpp>
+#include <yaml-cpp/yaml.h>
+
+glb_init()
+{
+  CDebug("Initializing per-client connection exempt list plugin");
+  if (instance.Size() != 1) {
+    TSError("Expected exempt list filepath as argument, none provided.");
+    return;
+  }

Review Comment:
   The error message is misleading when `instance.Size() > 1`. It says 'none 
provided' but should indicate either 'none provided' or 'too many arguments 
provided' depending on the actual size.
   ```suggestion
     if (instance.Size() == 0) {
       TSError("Expected exempt list filepath as argument, none provided.");
       return;
     }
     if (instance.Size() > 1) {
       TSError("Expected only exempt list filepath as argument, too many 
arguments provided.");
       return;
     }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to