Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/autest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib
export PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/gold_tests/remap:$PYTHONPATH
export PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/gold_tests/remap:${CMAKE_CURRENT_SOURCE_DIR}/gold_tests/lib:$PYTHONPATH

# Define tests to skip for CURL_UDS_FLAG
if [ -n "${CURL_UDS_FLAG}" ]; then
Expand Down
153 changes: 153 additions & 0 deletions tests/gold_tests/lib/ats_autest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
'''
Shared library code for ATS autest tests. Add and update this file as needed.
'''
# 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 glob
import os
import time


class ATSTestManager:
"""
A comprehensive test management class for Apache Traffic Server tests.
"""
host_example = "Host: www.example.com"
conn_keepalive = "Connection: keep-alive"

def __init__(self, Test, When, test_name="ts"):
"""
Initialize the ATSTestManager with ATS and origin server processes.
"""
self.Test = Test
self.When = When
self.ts = self.Test.MakeATSProcess(test_name)
self.server = self.Test.MakeOriginServer("server")

self.ats_port = self.ts.Variables.port
self.origin_port = self.server.Variables.Port
self.run_dir = self.Test.RunDirectory
self.localhost = f"127.0.0.1:{self.ats_port}"

self.started = False

# Default response header template
self.default_response_header = {
"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n",
"timestamp": "1469733493.993",
"body": ""
}

def enable_diagnostics(self, tags="http_hdrs"):
"""
Configure debug logging for the ATS process.
"""
self.ts.Disk.records_config.update(
{
'proxy.config.diags.debug.enabled': 1,
'proxy.config.diags.show_location': 0,
'proxy.config.diags.debug.tags': tags,
})

def add_server_responses(self, responses, log_file="sessionfile.log"):
"""
Add responses to the origin server for the given request/response pairs.
"""
for req, resp in responses:
if resp is None:
resp = self.default_response_header
self.server.addResponse(log_file, req, resp)

def add_remap_rules(self, remap_rules, disable_tls=True):
"""
Add remap rules to the ATS configuration.
This method processes a list of remap rule dictionaries and adds them to the
remap.config file. Each rule can have associated plugins with parameters.
"""
for rule in remap_rules:
plugin_args = self._build_plugin_args(rule["plugins"])

self.ts.Disk.remap_config.AddLine(f'map http://{rule["from"]} http://{rule["to"]} {plugin_args}')
if not disable_tls:
self.ts.Disk.remap_config.AddLine(f'map https://{rule["from"]} http://{rule["to"]} {plugin_args}')

def _build_plugin_args(self, plugins):
"""
Build plugin arguments string from plugins list.
"""
if not plugins:
return ""

return " ".join(f'@plugin={plugin}.so ' + " ".join(f'@pparam={p}' for p in params) for plugin, params in plugins)

def execute_tests(self, test_runs):
"""
Execute all configured test runs.
"""
for test in test_runs:
if not 'desc' in test:
raise ValueError("Test run must include 'desc' key")
tr = self.Test.AddTestRun(test["desc"])

# Start processes before the first test
if not self.started:
tr.Processes.Default.StartBefore(self.server, ready=self.When.PortOpen(self.origin_port))
tr.Processes.Default.StartBefore(self.ts)
self.started = True

if curl := test.get("curl"):
tr.MakeCurlCommand(curl, ts=self.ts)
elif multi := test.get("multi_curl"):
tr.MakeCurlCommandMulti(multi, ts=self.ts)

if gold := test.get("gold"):
tr.Processes.Default.Streams.stderr = gold

tr.StillRunningAfter = self.server

def set_traffic_out_content(self, content_file):
"""
Set the traffic.out content file for debugging.
Args:
content_file (str): Path to the content file
"""
self.ts.Disk.traffic_out.Content = content_file

def copy_files(self, source, pattern, destination_dir=None):
"""
Copy files using either glob pattern matching or explicit file list.
This method supports two modes:
1. Pattern matching: When source is a string directory path, it finds all files
matching the glob pattern and copies them to the destination.
2. Explicit file list: When source is a list of file paths, it copies each
file directly (pattern parameter is ignored in this case).
"""
if destination_dir is None:
destination_dir = self.run_dir

if isinstance(source, list):
for file_path in source:
self.ts.Setup.CopyAs(file_path, destination_dir)
elif pattern is not None:
for file_path in glob.glob(os.path.join(self.Test.TestDirectory, source, pattern)):
relative_path = os.path.relpath(file_path, self.Test.TestDirectory)
self.ts.Setup.CopyAs(relative_path, destination_dir)
else:
raise ValueError("Either 'source' must be a list of files or 'pattern' must be provided with a source directory.")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
``
> GET ``/from_path/hrw-sets.png``
> GET http://www.example.com/from_1/hrw-sets.png``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unique URL is helpful, but let's not use sequential numbers or letters. Inserting tests would be painful.

Copy link
Contributor Author

@zwoop zwoop Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that be painful? I guess I don't really care what we name them, but they have to be named something :). I'd imagined that if you are adding a new test to an existing autest, you append to the current list of remap rules if you need a new one. Sequential numbering. There'd never be a reason to add a rule in the middle of remap rules I don't think. If there is, at some point, just name it /from_x_y ? E.g. /from_4_1.

We could automate the numbering, but when I looked at that, it makes making the subsequent tests more difficult (you need some sort of identifier).

Copy link
Contributor Author

@zwoop zwoop Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, note that it's not the request that's unique, it's the remap rule. One remap rule can handle multiple requests (test cases).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There'd never be a reason to add a rule in the middle of remap rules I don't think. If there is, at some point, just name it /from_x_y ? E.g. /from_4_1.

I think similar test cases should be close each other. We could do "4_1", but that doesn't completely resolve the issue. Let's say we have "4_1", "4_2", and "4_3". If I wanted to insert a test between "4_1" and "4_2", I'd have to make "4_1_1" or renumber "4_2" and "4_3".

Also even for the case that I append tests, somebody else could be appending another tests on the same file. Then the number would conflicts. Either of those have to update the test number.

I don't think whether tests or remap rules matters in this discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the order doesn't matter. It's just an identifier, which I thought was easier to make numbered, but we can call them bob and alice if you want ...

> Host: www.example.com``
> User-Agent: curl/``
``
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
``
> GET / HTTP/1.1
> GET /from_5/ HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 200 OK
< Cache-Control: max-age=10,public
< Content-Length: 6
< Date: ``
< Age: ``
< Connection: keep-alive
< Server: ATS/{}
< Cache-Result: miss
``
> GET / HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 200 OK
< Cache-Control: max-age=10,public
< Cache-Control: max-age=5,public
< Content-Length: 6
< Date: ``
< Age: ``
< Connection: keep-alive
< Server: ATS/{}
< Cache-Result: hit-fresh
``
> GET / HTTP/1.1
> GET /from_5/ HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 200 OK
< Cache-Control: max-age=10,public
< Cache-Control: max-age=5,public
< Content-Length: 6
< Date: ``
< Age: ``
< Connection: keep-alive
< Server: ATS/{}
< Cache-Result: hit-stale
``
> GET / HTTP/1.1
> GET /from_5/ HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 200 OK
< Cache-Control: max-age=10,public
< Cache-Control: max-age=5,public
< Content-Length: 6
< Date: ``
< Age: ``
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
``
> GET /from_5/ HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 200 OK
< Cache-Control: max-age=5,public
< Content-Length: 6
< Date: ``
< Age: ``
< Connection: keep-alive
< Server: ATS/{}
< Cache-Result: miss
``
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
``
> GET /hello HTTP/1.1
> GET /from_4/hello HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
Expand All @@ -13,7 +13,7 @@
< Connection: keep-alive
<
``
> GET /hello HTTP/1.1
> GET /from_4/hello HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
Expand All @@ -27,7 +27,7 @@
< Connection: keep-alive
<
``
> GET /hello HTTP/1.1
> GET /from_4/hello HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
Expand All @@ -41,7 +41,7 @@
< Connection: keep-alive
<
``
> GET /hello HTTP/1.1
> GET /from_4/hello HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
Expand All @@ -55,7 +55,7 @@
< Connection: close
<
``
> GET /world HTTP/1.1
> GET /from_4/world HTTP/1.1
> Host: www.example.com
> User-Agent: curl/``
> Accept: */*
Expand All @@ -68,4 +68,4 @@
< Age: ``
< Connection: close
<
``
``
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
``
> GET ``/from_path/hrw-sets.png``
> GET http://www.example.com/from_1/hrw-sets.png``
> Host: www.example.com``
> User-Agent: curl/``
``
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
``
> GET ``
> Host: www.example.com``
> User-Agent: curl/``
> Accept: */*
> Proxy-Connection: Keep-Alive
> X-Fie: Fie
``
< HTTP/1.1 200 OK
< Date: ``
< Age: ``
< Transfer-Encoding: chunked
< Proxy-Connection: keep-alive
< Server: ATS/``
< X-Response-Foo: Yes
``
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
``
> GET ``
> Host: www.example.com``
> User-Agent: curl/``
> Accept: */*
> Proxy-Connection: Keep-Alive
``
< HTTP/1.1 200 OK
< Date: ``
< Age: ``
< Transfer-Encoding: chunked
< Proxy-Connection: keep-alive
< Server: ATS/``
< X-Response-Foo: No
``
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
``
> GET ``
> Host: www.example.com``
> User-Agent: curl/``
> Accept: */*
> Proxy-Connection: Keep-Alive
> X-Client-Foo: fOoBar
``
< HTTP/1.1 200 OK
< Date: ``
< Age: ``
< Transfer-Encoding: chunked
< Proxy-Connection: keep-alive
< Server: ATS/``
< X-Response-Foo: Prefix
``
Loading