Copilot commented on code in PR #13237:
URL: https://github.com/apache/trafficserver/pull/13237#discussion_r3353113246
##########
tests/gold_tests/remap/remap_acl.test.py:
##########
@@ -166,13 +169,13 @@ def _configure_traffic_server(self) -> int:
#
tr = Test.AddTestRun("Await config reload")
p = tr.Processes.Default
- p.Command = 'echo awaiting config reload'
- p.Env = ts.Env
Test_remap_acl._ts_reload_counter += 1
- count = Test_remap_acl._ts_reload_counter
- await_config_reload =
tr.Processes.Process(f'config_reload_succeeded_{count}', 'sleep 30')
- await_config_reload.Ready =
When.FileContains(ts.Disk.diags_log.Name, "remap.config finished loading",
count)
- p.StartBefore(await_config_reload)
+ count = 1 + Test_remap_acl._ts_reload_counter
+ p.Command = (
+ f'{sys.executable} {shlex.quote(_wait_for_file_contains)} '
+ f'{shlex.quote(ts.Disk.diags_log.Name)}
{shlex.quote("remap.config finished loading")} {count}')
Review Comment:
`p.Command` builds a shell command with `shlex.quote()` for the script path
and arguments, but `sys.executable` itself is left unquoted. If the Python
executable path contains spaces (e.g., uncommon but possible in some
environments), the command will break before it ever reaches the helper script.
##########
tests/gold_tests/remap_yaml/remap_acl_yaml.test.py:
##########
@@ -175,13 +178,13 @@ def _configure_traffic_server(self) -> int:
#
tr = Test.AddTestRun("Await config reload")
p = tr.Processes.Default
- p.Command = 'echo awaiting config reload'
- p.Env = ts.Env
Test_remap_acl._ts_reload_counter += 1
- count = Test_remap_acl._ts_reload_counter
- await_config_reload =
tr.Processes.Process(f'config_reload_succeeded_{count}', 'sleep 30')
- await_config_reload.Ready =
When.FileContains(ts.Disk.diags_log.Name, "remap.yaml finished loading", count)
- p.StartBefore(await_config_reload)
+ count = 1 + Test_remap_acl._ts_reload_counter
+ p.Command = (
+ f'{sys.executable} {shlex.quote(_wait_for_file_contains)} '
+ f'{shlex.quote(ts.Disk.diags_log.Name)}
{shlex.quote("remap.yaml finished loading")} {count}')
Review Comment:
Same quoting issue as in the remap.config test: `sys.executable` is not
shell-quoted while other command components are. Quoting it makes the wait
command robust to Python interpreter paths that contain spaces.
##########
tests/gold_tests/lib/wait_for_file_contains.py:
##########
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+"""Wait for a file to contain a pattern a given number of times."""
+
+# 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 pathlib
+import sys
+import time
+
+
+def main() -> int:
+ path = pathlib.Path(sys.argv[1])
+ pattern = sys.argv[2]
+ count = int(sys.argv[3])
+ timeout = float(sys.argv[4]) if len(sys.argv) > 4 else 30
Review Comment:
`wait_for_file_contains.py` assumes the required CLI arguments are present
and valid. If it’s ever called incorrectly (or a bad value is passed for
`count` / `timeout`), it will raise an `IndexError`/`ValueError` and produce a
Python traceback rather than a concise usage/error message.
--
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]