Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing

Meridian requires every component to have all test layers: unit tests, integration tests, and benchmarks for hot-path code.

Running Tests

# All tests
cargo test --workspace

# Core library only
cargo test -p meridian-core

# Proxy unit + integration tests
cargo test -p meridian-proxy

# Integration tests only
cargo test -p meridian-proxy --test integration

# Single test
cargo test -p meridian-core -- chunked_single_chunk

Test Structure

Unit Tests (97 total)

In-module #[cfg(test)] blocks testing individual functions:

ModuleTestsWhat’s Covered
buffer5Slab acquire/release, BufChain operations, watermarks
codec22HTTP parsing, body framing, smuggling rejection, chunked encoding
config2Config store load/swap, route lookup
filter16Chain execution order, short-circuit, metadata, error propagation
health8Threshold logic, TCP/HTTP checks
load_balancing4Round-robin, Maglev consistency/disruption
observability4Counters, gauges, histograms, snapshots
pool6Checkout/checkin, max idle, expiry eviction
resilience4Circuit breaker RAII, token bucket, retry, outlier detection
tls4Cert loading, error display
conn_limit4Per-IP limits, RAII guards
connection7Path normalization

Integration Tests (15 total)

End-to-end tests in meridian-proxy/tests/integration.rs that spin up mock backends and proxy instances:

TestWhat’s Verified
Round-robin distribution4 requests alternate between 2 backends
Circuit breaker rejectionRequests rejected when CB limit reached
Connect timeout504 returned on unreachable backend
HTTP path routingPrefix matching routes to correct cluster
Path traversal prevention/../ normalized before routing
Opaque error responsesNo cluster names or IPs in error bodies
Filter chain header injectResponse filter adds header
Filter chain request rejectRequest filter returns 403
Health check failoverUnhealthy endpoint skipped by LB
Connection pool reuse4 requests, 1 upstream TCP connection
Chunked responseDechunked upstream response forwarded
Chunked request bodyChunked request body forwarded
TLS terminationFull HTTPS flow with self-signed cert
Admin API/stats, /clusters, /config, /ready endpoints
HTTP/2 proxyh2 client → proxy → h1 upstream → h2 response

Test Patterns

  • Mock backends use TcpListener::bind("127.0.0.1:0") for OS-assigned ports
  • Integration tests sleep 50ms after spawning servers to ensure they’re listening
  • TLS tests use rcgen for runtime-generated self-signed certificates
  • Tests use Connection: close to avoid keep-alive interactions