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


##########
tests/gold_tests/query/query-retry.test.py:
##########
@@ -0,0 +1,80 @@
+'''
+Verify QUERY is not retried once its request, content included, has been sent
+to an origin that then closes the connection, whether or not request buffering
+is enabled.
+'''
+#  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.
+
+import re
+import shlex
+import sys
+
+from ports import get_port
+
+Test.Summary = '''
+Verify QUERY is not retried once its request, content included, has been sent
+to an origin that then closes the connection, whether or not request buffering
+is enabled.
+'''
+
+Test.ContinueOnFail = True
+
+BODY = 'SELECT * FROM t WHERE a'
+
+
+def add_scenario(name: str, method: str, buffering: bool) -> None:
+    tr = Test.AddTestRun(f'{method} after the origin closes, request buffering 
{"enabled" if buffering else "disabled"}')
+    tr.Setup.Copy('query_retry_origin.py')
+
+    server = Test.Processes.Process(f'origin-{name}')
+    server_port = get_port(server, 'http_port')
+    server.Command = f'{sys.executable} 
{tr.RunDirectory}/query_retry_origin.py {server_port}'
+    server.Ready = When.PortOpen(server_port)
+
+    ts = Test.MakeATSProcess(f'ts-{name}')
+    ts.Disk.records_config.update(
+        {
+            'proxy.config.http.request_buffer_enabled': 1 if buffering else 0,
+            'proxy.config.http.connect_attempts_max_retries': 3,
+            'proxy.config.diags.debug.enabled': 1,
+            'proxy.config.diags.debug.tags': 'http_trans',
+        })
+    ts.Disk.remap_config.AddLine(f'map / http://127.0.0.1:{server_port}/')
+
+    content = f"-H 'Content-Type: application/sql' --data-binary 
{shlex.quote(BODY)} " if method == 'QUERY' else ''
+    tr.Processes.Default.StartBefore(server)
+    tr.Processes.Default.StartBefore(ts)
+    tr.Processes.Default.Command = (
+        f"curl -s -o /dev/null -w '%{{http_code}}\\n' -X {method} 
{content}http://127.0.0.1:{ts.Variables.port}/search";)

Review Comment:
   The test curl invocation has no explicit timeout; if ATS or the origin 
hangs, this can stall the test run indefinitely. Add a bounded timeout (e.g., 
curl's max-time and/or connect-timeout) so failures terminate quickly and 
predictably.



##########
tests/gold_tests/autest-site/ats_replay.test.ext:
##########
@@ -159,9 +159,14 @@ def configure_ats(obj: 'TestRun', server: 'Process', 
ats_config: dict, dns: Opti
 
     # Configure logging.yaml if specified.
     logging_yaml = ats_config.get('logging_yaml')
-    if logging_yaml != None:
+    if logging_yaml is not None:
         ts.Disk.logging_yaml.AddLines(yaml.dump(logging_yaml).split('\n'))
 
+    # Configure ip_allow.yaml if specified.
+    ip_allow_yaml = ats_config.get('ip_allow_yaml')
+    if ip_allow_yaml is not None:
+        ts.Disk.ip_allow_yaml.AddLines(yaml.dump(ip_allow_yaml).split('\n'))

Review Comment:
   For serializing YAML config content, prefer `yaml.safe_dump(...)` over 
`yaml.dump(...)` to avoid emitting/accepting unsafe Python-specific tags (even 
in tests this helps keep output predictable). Also consider using 
`splitlines()` instead of `split('\\n')` to avoid an extra trailing empty line 
entry.



##########
tests/gold_tests/query/query_retry_origin.py:
##########
@@ -0,0 +1,82 @@
+'''
+An origin that closes the first connection after reading the request, without
+responding, and answers every later request with a 200.
+'''
+#  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.
+
+import argparse
+import socket
+import sys
+
+
+def read_request(conn: socket.socket) -> tuple[str, bytes]:
+    data = bytearray()
+    while b'\r\n\r\n' not in data:
+        chunk = conn.recv(4096)
+        if not chunk:
+            return '', b''
+        data += chunk
+    head, _, body = data.partition(b'\r\n\r\n')
+    lines = head.decode('latin-1').split('\r\n')
+    method = lines[0].split(' ')[0]
+    length = 0
+    for line in lines[1:]:
+        name, _, value = line.partition(':')
+        if name.strip().lower() == 'content-length':
+            length = int(value.strip())
+    while len(body) < length:
+        chunk = conn.recv(4096)
+        if not chunk:
+            break
+        body += chunk
+    return method, bytes(body[:length])

Review Comment:
   In the body-read loop, `body` is a `bytes` object and `body += chunk` 
repeatedly reallocates/copies, which can become quadratic for larger payloads. 
Use a `bytearray` (or reuse the existing `data` buffer) for incremental reads 
and convert/slice once at the end.



-- 
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