Guides / Testing & Validation

Testing & Validation

Ferrum Edge ships its test tooling in the gateway itself: config validation, backend mocking, chaos fault injection, shadow traffic mirroring, and on-demand load testing — plus reproducible benchmark suites in the repository.

Validate Configuration Before You Deploy

The validate subcommand checks a config without starting the gateway — perfect as a CI gate.

bash
# Validate a file-mode spec
ferrum-edge validate --spec resources.yaml

# Validate settings + spec together
ferrum-edge validate --settings /etc/ferrum/ferrum.conf --spec /etc/ferrum/resources.yaml

# Pin the mode so CI never depends on the runner's environment
ferrum-edge validate --mode file --spec resources.yaml

# Use as a CI gate — exit status 1 on any error
ferrum-edge validate --spec resources.yaml || exit 1

Validation runs the same admission checks as startup: schema version, duplicate listen paths, unknown fields, plugin configs, credential rules, references, namespace filtering, and TLS and admin security settings. It never binds a port or connects to a database. Review the warnings as well: an invalid optional observability plugin is reported and dropped rather than failing the run.

Smoke-Test a Running Gateway

bash
# Liveness — no auth, always {"status":"ok"} while the process runs
curl http://localhost:9000/live

# Readiness — no auth returns status+ready; full diagnostics require a JWT
curl http://localhost:9000/health

# Authenticated deep health + runtime metrics snapshot
curl -H "Authorization: Bearer $TOKEN" http://localhost:9000/health
curl -H "Authorization: Bearer $TOKEN" http://localhost:9000/metrics/runtime

# Send a request through a configured proxy
curl -i http://localhost:8000/api/v1/hello
# On errors, X-Gateway-Error and X-Gateway-Upstream-Status headers explain why
ℹ️
Debugging a request? Attach the transaction_debugger plugin to a proxy in development and set FERRUM_LOG_LEVEL=debug. It logs each request and response with its terminal outcome, timing, and rejection phase, with sensitive headers redacted.

Mock Backends with response_mock

Develop and contract-test against APIs that don't exist yet — rules use paths relative to the proxy’s prefix listen path, and unmatched requests can pass through to the real backend. The examples below are plugin fragments: merge them into a versioned gateway config and attach the IDs in your proxy’s plugins list.

yaml
plugin_configs:
  - id: "orders-mock"
    plugin_name: "response_mock"
    scope: proxy
    proxy_id: orders-api
    enabled: true
    config:
      passthrough_on_no_match: true   # unmatched requests hit the real backend
      rules:
        - method: GET
          path: "~/[0-9]+"             # relative to a proxy listening on /orders
          status_code: 200
          headers:
            content-type: application/json
          body: '{"id": 1, "status": "shipped"}'
          delay_ms: 150                # simulate realistic latency
        - method: POST
          path: "/"
          status_code: 201
          body: '{"id": 2, "status": "created"}'

Chaos-Test Clients with fault_injection

Prove your clients handle failure before production does it for you. Works on HTTP, gRPC, TCP, and UDP.

yaml — HTTP aborts and latency
plugin_configs:
  - id: "chaos-http"
    plugin_name: "fault_injection"
    scope: proxy
    proxy_id: orders-api
    enabled: true
    config:
      abort:
        percentage: 5.0     # 5% of matched requests
        status_code: 503
      delay:
        percentage: 20.0    # 20% of matched requests
        duration_ms: 500
      match:
        headers:
          x-chaos-test: "1" # only fault marked traffic
yaml — TCP / UDP stream faults
plugin_configs:
  - id: "chaos-stream"
    plugin_name: "fault_injection"
    scope: proxy
    proxy_id: orders-tcp      # a TCP stream proxy
    enabled: true
    config:
      abort:
        percentage: 2.0
        status_code: 503
      delay:
        percentage: 10.0
        duration_ms: 200

Each instance samples independently, so proxy- and group-scoped experiments stay isolated and you can chaos-test one route without touching the rest of the gateway. match.headers limits HTTP faults to marked requests on a live route, and every delay is capped at one minute.

Shadow-Test with request_mirror

Duplicate a sample of live traffic to a new service version. Fire-and-forget — the mirror can be slow or down without affecting a single client response.

yaml
plugin_configs:
  - id: "shadow-v2"
    plugin_name: "request_mirror"
    scope: proxy
    proxy_id: orders-api
    enabled: true
    config:
      mirror_protocol: https
      mirror_host: "orders-v2.internal"
      mirror_port: 443
      percentage: 10.0     # deterministic, evenly spaced sampling
      mirror_request_body: true          # include bodies (bounded budgets apply)

Mirror outcomes flow into transaction logs and Prometheus counters (ferrum_request_mirror_*), so you can compare the shadow service's behavior against production before cutting over. Credential headers and query parameters are stripped from mirrored requests unless you explicitly allowlist them.

On-Demand Load Tests with load_testing

Trigger a load test with a single header — the gateway spawns virtual clients that send requests back through its own proxy listener, exercising the full pipeline: routing, auth, rate limiting, backend dispatch, and logging.

yaml — attach the plugin
plugin_configs:
  - id: "loadtest"
    plugin_name: "load_testing"
    scope: proxy
    proxy_id: orders-api
    enabled: true
    config:
      key: "replace-with-a-random-secret-at-least-32-chars"
      concurrent_clients: 200
      duration_seconds: 30
      ramp: true
      gateway_port: 8000
      gateway_tls: false
      # Fan out to remote gateway instances for multi-node tests:
      # gateway_addresses: ["https://gw-2:8443", "https://gw-3:8443"]
bash — trigger it
export LOADTEST_KEY="replace-with-a-random-secret-at-least-32-chars" # match config.key
curl -H "X-Loadtesting-Key: $LOADTEST_KEY" http://localhost:8000/orders/1
# Watch results in your metrics: latency histograms, status windows, pool stats
curl -H "Authorization: Bearer $TOKEN" http://localhost:9000/metrics/runtime

This trigger assumes orders-api listens on /orders and references plugin_config_id: loadtest. Use your proxy’s actual path when adapting the fragment.

Run the Repository Test & Benchmark Suites

Building from source? The repo includes the full test pyramid and the reproducible benchmark harnesses behind our published numbers.

bash
git clone https://github.com/ferrum-edge/ferrum-edge.git
cd ferrum-edge

# Prerequisites: Rust stable and protoc (see CONTRIBUTING.md); the bootstrap
# script installs the other native build tools but not Rust or protoc
./scripts/install-build-deps.sh

# Default-feature unit/integration tests; see CONTRIBUTING.md for E2E prerequisites
cargo test

# Lint at CI strictness
cargo clippy --all-targets -- -D warnings
cargo fmt --check

# Multi-protocol performance suite (HTTP/1.1/2/3, gRPC, WS, TCP, UDP)
# Requires lsof, python3 and curl; see tests/performance/multi_protocol/README.md for options
./tests/performance/multi_protocol/run_protocol_test.sh all

# Docker gateway comparison harness (Ferrum vs Envoy, Kong, Tyk, KrakenD)
# Needs a running Docker daemon; see comparison/README.md for prerequisites
./comparison/run_comparison.sh

# In-process Istio and xDS conformance suite, run the way CI runs it: one test
# thread so the report lists every case, plus the strict GA-contract gate
FERRUM_CONFORMANCE_STRICT_GATE=1 cargo test --test conformance_tests -- --test-threads=1
ℹ️
Functional test guides: the repository documents scenario-based functional testing for auth/ACL, database modes, file mode, and load/stress in docs/functional_testing.md and its companions — useful as templates for testing your own configuration.