This document describes the test architecture for Pavis. It serves as the primary entry point for understanding how to run and write tests.
Detailed Design Specifications:
- Runtime Suite Design - Focuses on the
pavisdata plane binary. - Relay Suite Design - Focuses on the
pavis-relaycontrol plane. - Integrated Suite Design - Focuses on end-to-end system integration.
Pavis tests are organized into three distinct suites, each with a clear responsibility:
- Runtime Suite: Verifies the
pavisruntime proxy in isolation, including hot-reload and last-known-good semantics. - Relay Suite: Tests the
pavis-relaycontrol plane independently, focusing on fanout, long-poll, and artifact distribution. - Integrated Suite: End-to-end validation of the complete system path (pavctl → relay → runtime → upstream).
- Clear Responsibility: Each suite tests a specific component or integration boundary.
- Faster Feedback: Unit-level suites (runtime, relay) run faster and fail earlier than full integration tests.
- Better Failure Isolation: When a test fails, the suite name immediately narrows the search space.
All three suites share a common foundation provided by pavis-testkit, a workspace crate containing non-production test fixtures.
- Provides deterministic mock services for testing.
- Ensures consistent behavior across binary, Docker, and future Kubernetes environments.
- Simplifies test authoring by abstracting environment setup.
pavis-testkit provides two binaries:
- Purpose: Deterministic upstream HTTP/HTTPS service for testing runtime behavior.
- Capabilities:
- Verifies routing, header manipulation, TLS origination.
- Simulates failure scenarios (503s, timeouts, flakiness).
- Exposes observability endpoints (
/received,/reset) for assertions.
- Not Production Code: This binary exists only for testing and is never deployed.
- Purpose: Minimal mock control plane for testing runtime hot-reload without restarts.
- Capabilities:
- Implements long-poll artifact distribution (opaque bytes only).
- Provides
/publishendpoint to inject new.pvsartifacts during tests. - Treats artifacts as opaque byte blobs (no parsing, no semantic validation).
- Design Constraint: The runtime hot-reload mechanism requires a live control plane. Since production
pavis-relayis heavyweight and couples with external dependencies,pavis-mock-relayprovides the minimal interface needed to test runtime-only semantics.
- Focus:
pavisbinary. - Topology:
pavis+pavis-mock-relay+pavis-mock-upstream. - Key Validation: Hot reload, LKG, Routing logic, Resilience policies.
- Focus:
pavis-relaybinary. - Topology:
pavis-relay(isolated). - Key Validation: API contract, Long-poll blocking, Fanout, Persistence, Limits.
- Focus: System interaction.
- Topology:
pavctl+pavis-relay+pavis+pavis-mock-upstream. - Key Validation: End-to-End publishing, Real-world reload, Component compatibility.
The same test logic can run in multiple environments:
-
Binary Mode (default):
- Components are launched as native binaries.
- Fastest execution.
- Default for local development and CI.
-
Docker / Docker Compose:
- Components run in containers.
- Uses
pavis-testkit:localand other local images. - Validates containerized deployment.
Environment differences affect how components are launched, not what is tested. The same test cases run in all environments with identical assertions.
The following sections provide detailed guidance for writing individual test cases within the three suites.
An E2E case in this repository is responsible for verifying a specific behavior of the Pavis proxy against a controlled upstream.
- Configure Pavis: Provide a valid configuration (file or inline).
- Generate Traffic: Send HTTP/TCP requests through Pavis.
- Assert Behavior: Verify the response from Pavis or the state of the upstream.
- Infrastructure: Do NOT manage Docker containers, networks, or volumes. The runner handles this.
- Lifecycle: Do NOT start or stop the Pavis process manually unless testing crash recovery. The harness handles the primary process.
- Complex Logic: Keep scripts linear. Avoid complex loops or conditionals.
Every case script MUST follow this canonical structure:
#!/bin/bash
# Case: [Name]
# Scenario: [Brief description of what is being tested]
# 1. Imports
source "$(dirname "$0")"/../../scripts/env.sh"
source "$(dirname "$0")"/../../scripts/assert.sh"
# 2. Configuration & Inputs
# Define variables or write config files relative to the case execution
setup_test "10_bootstrap"
cleanup_trap() { cleanup_test; }
trap cleanup_trap EXIT
PORT_PAVIS=$(get_free_port)
# 3. Execution
# Start Pavis or apply config
run_pavis ...
# 4. Traffic Generation
# Send requests with MANDATORY isolation headers
response=$(curl_pavis "/api/resource" \
-H "X-Pavis-Test-Case: ${CASE_NAME}" \
-H "X-Pavis-Test-Run: ${RUN_ID}")
# 5. Assertions
# Validate HTTP status, headers, or upstream observations
assert_status 200 "$response"To ensure determinism and allow for clear log tracing, EVERY request sent through Pavis MUST include the following headers:
X-Pavis-Test-Run: Identifies the specific CI run or test session.X-Pavis-Test-Case: Identifies the specific test case file/function.
- State Isolation: The upstream uses these headers to namespace counters (e.g., for
/flakyor/received). - Debugging: Traces logs clearly to a specific test case.
Use the run.sh script:
# Run all suites (binary mode)
./tests/run.sh
# Run specific suite
./tests/run.sh pavis
./tests/run.sh relay
./tests/run.sh integrated
# Run specific case
./tests/run.sh pavis 10_bootstrap_static
./tests/run.sh integrated 10_bootstrap_pathThe runner writes a run-scoped context.env at tests/temp/context.env and copies it into each case's TEST_TMP directory. This file is shell-sourceable and captures the runtime context for debugging and audit.
Admin API Tests (00_operational_admin_api.sh):
- Scope: Verifies read-only admin API endpoints (
/health,/stats) - Assertions:
/healthreturns{"status":"healthy"}with 200 OK/statsreturns JSON with required fields (version, uptime_seconds, listeners, upstreams, routes)- Config counts in
/statsreflect actual runtime configuration (listeners=1, upstreams=2, routes=2) - Uptime counter increases over time
- Unknown paths return 404
- Admin API isolated to admin port only (not accessible on traffic port)
- Traffic routing unaffected by admin API presence
- Configuration: Admin enabled on separate port, shutdown disabled for test speed
Graceful Shutdown Tests (01_operational_graceful_shutdown.sh):
- Scope: Verifies SIGTERM triggers graceful drain of in-flight requests
- Topology: Pavis + slow mock upstream (3s response delay)
- Assertions:
- In-flight request initiated before SIGTERM completes successfully
- Response content is valid and matches expected upstream instance
- Request duration matches upstream delay (~3s)
- Pavis exits within drain_timeout (5s) + request duration + buffer
- Shutdown duration within expected bounds (<10s total)
- Configuration: Graceful shutdown enabled with 5s drain timeout
- Test Pattern: Background request → SIGTERM → verify completion → verify exit
Key Behaviors Verified:
- Admin API Security: Bind-address isolation (admin port ≠ traffic port)
- Admin API Read-Only: No mutation endpoints, informational data only
- Graceful Drain: In-flight requests complete during drain phase
- Fail-Closed Shutdown: New connections rejected after SIGTERM
- Bounded Shutdown: Process exits within configurable timeout
Non-Goals (Explicitly Not Tested):
- Admin API authentication (Phase 7 has no auth - bind to loopback for security)
- Shutdown admin endpoint (Phase 7 only supports SIGTERM/SIGINT signals)
- WebSocket/SSE connection drain (not supported in Phase 7)
- Config reload during shutdown (undefined behavior, deferred)