This directory implements the pytest framework used by Traffic Server's Uranium system tests. Test cases live in tests/uranium_tests; this directory contains collection, configuration, execution, process, and fixture support.
See the test-suite README for commands and the Uranium developer guide for test-authoring guidance.
The framework has five layers:
| Layer | Main module | Responsibility |
|---|---|---|
| Command entry point | runner.py | Select the host or container environment and invoke pytest. |
| Pytest integration | plugin.py | Collect replay files, create pytest items, apply markers, and provide fixtures. |
| Test specification | config.py | Parse and validate replay metadata into ReplaySpec objects. |
| Test execution | replay.py | Materialize a sandbox, run the declared processes, and validate results. |
| Runtime primitives | runtime.py, process.py, expectations.py, and services/ | Discover programs, own processes, express expected output, and provide procedural-test APIs. |
The short distinction between the three replay-facing modules is:
plugin.py adapts replay files to pytest.config.py determines what a replay test means.replay.py makes that test happen.A direct replay test is a *.test.yaml or *.test.yml file. One file can serve two related purposes:
urtest mapping describes test orchestration, ATS configuration, requirements, and expected results.urtest.replay can name a separate traffic file.The execution path is:
runner.py prepares the selected environment and starts pytest with plugin.py loaded.plugin.py::pytest_collect_file() recognizes the replay suffix and creates a ReplayFile collector.ReplayFile.collect() calls config.py::ReplaySpec.load_all(). The loader reads YAML, validates the urtest mapping, resolves the traffic file, and merges any variants.ReplayItem per ReplaySpec, including one item per variant, and applies replay and manual markers.ReplayItem.runtest() obtains a TestRuntime and passes the validated specification to replay.py::ReplayTest.ReplayTest.run() creates the sandbox, starts DNS and Proxy Verifier as requested, materializes and starts ATS, runs the client, validates files, metrics, logs, and process output, and finally stops every process.config.py also contains small ATS-configuration serialization helpers used by replay.py, such as flat-record conversion and YAML writing. Those helpers operate on data; process orchestration remains in replay.py.
Tests that require custom clients, servers, runtime mutations, or multiple ATS instances are ordinary test_*.py modules:
plugin.py supplies fixtures such as ats, ats_factory, curl, procedural_context, and services.services/context.py identifies the test's sandbox and source directory.services/ats.py owns ATS instances, while services/service_factory.py owns origins, DNS servers, Proxy Verifier processes, and other support programs.process.py for lifecycle and output capture, and runtime.py for installed paths, features, ports, and sandboxes.The procedural ATS service reuses ATS setup and startup functionality from ReplayTest. This keeps direct replay and procedural ATS behavior consistent, although it means replay.py is also an implementation dependency of procedural tests.
assertions.pyDefines assertions shared by direct replay and procedural tests. Gold-file matching lives here, including the optional cdifflib acceleration and the standard-library fallback.
config.pyDefines ReplaySpec and ReplayConfigError. It loads replay manifests, validates required metadata, expands variants, resolves replay paths, merges flat ATS records, formats plugin entries, substitutes ports, and writes YAML. It does not start processes.
expectations.pyDefines the explicit process-stream expectation API shared by managed procedural services. It accumulates contains(), excludes(), and matches_gold() declarations, supports intentional reset(), and rejects the legacy += registration form. process.py owns each stream object and ProcessService validates it after a process completes or is stopped.
plugin.pyDefines pytest hooks, custom replay collectors and items, markers, sharding, serial scheduling, manual-test selection, and the public Uranium fixtures. It connects pytest to ReplaySpec, ReplayTest, and the procedural services.
CI shards are assigned by a CRC32 hash of each test id, so a test keeps its shard when other tests are added or removed. Rerunning one failed shard reruns the same tests.
process.pyDefines the low-level ManagedProcess primitive and ProcessError. ManagedProcess owns subprocess startup, readiness polling, signals, captured stdout and stderr, explicit stream and return-code expectations, timeouts, and cleanup.
replay.pyDefines the direct-replay execution engine. It prepares ATS configuration and run-root files, launches the declared server, ATS, DNS, and client processes, runs lifecycle commands, replaces runtime placeholders, and validates expected outputs.
runner.pyImplements the Python entry point used by tests/urtest.sh and generated build-tree wrappers. It separates wrapper options from pytest arguments, selects Apple container, Podman, Docker, or direct execution, prepares the container build, handles CI shards, chooses a short sandbox path, and restores artifact ownership.
runtime.pyDefines TestRuntime, the immutable description of one installed test environment. It discovers ATS and helper programs, reads build features and layout, allocates ports, creates readable per-test sandboxes, resolves generated artifacts, and coordinates execution that must be exclusive.
utils.pyDefines small address, TCP-readiness, and version helpers shared by the replay engine and procedural services.
services/ packageservices/__init__.py is the stable public facade used by procedural tests:
from tools.uranium.services import ATS, Curl, ServiceFactory
The implementations are divided by responsibility:
| Module | Responsibility |
|---|---|
ats.py | ATS configuration, lifecycle, tools, logs, signals, and ATSFactory. |
context.py | ProceduralContext sandbox state and CommandResult values. |
curl.py | Curl execution and ATS-aware TCP or Unix-domain-socket transport. |
process_service.py | Procedural wrapper around ManagedProcess, adding readiness and output validation. |
origin.py | Microserver lifecycle and programmatic request/response sessions. |
dns.py | MicroDNS lifecycle, readiness, and record updates. |
httpbin.py | go-httpbin lifecycle and readiness. |
verifier.py | Proxy Verifier server lifecycle and violation checks. |
service_factory.py | Creation and cleanup of non-ATS services and arbitrary support processes. |
service_utils.py | File polling, TCP requests, and metric polling. |
The distinction between the two process layers is intentional:
process.py::ManagedProcess is the general subprocess primitive.services/process_service.py::ProcessService adds behavior expected by procedural pytest scenarios.min_cfg/Contains the smallest baseline configuration copied into each ATS sandbox:
ip_allow.yaml provides safe default inbound and outbound access rules.storage.yaml provides a minimal cache storage span.readme.txt records why these baseline files are still necessary.tests/Contains fast framework tests rather than Traffic Server scenarios:
test_config.py covers metadata parsing, variants, replay inventory, and configuration transformations.test_assertions.py covers shared gold-file comparison and diff selection.test_plugin.py covers pytest marker, manual-test, and shard selection behavior.test_process.py covers subprocess handling and placeholder replacement.test_runner.py covers wrapper arguments, containers, sharding, builds, and sandbox copying.test_services.py covers the public service facade, ATS ownership, cleanup, Curl argument parsing, and Unix-domain-socket behavior.config.py.plugin.py.replay.py.runtime.py.process.py.services/ module.tests/.