Files
missions/scripts/run-performance-tests.sh
T
Oleksandr Bezdieniezhnykh 78dea8ebab
ci/woodpecker/push/build-arm Pipeline was successful
chore: update configuration and Docker setup for JWT and test results
Enhanced the .gitignore to exclude test results and updated the Dockerfile to include a new entrypoint script for improved container initialization. Refactored JWT configuration to support additional parameters for automatic refresh intervals, ensuring better control over token management. Updated the ConfigurationResolver to enforce required environment variables without hardcoded fallbacks, enhancing security and flexibility.
2026-05-15 03:23:23 +03:00

126 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
## Performance test runner for the missions service.
## Scenarios: NFT-PERF-01 (cascade P50 <=50ms), NFT-PERF-03 (health P50 <=10ms),
## NFT-PERF-02 (cascade with full chain, regression baseline), NFT-PERF-04
## (mission list P95, regression baseline). Spec lives in
## _docs/02_document/tests/performance-tests.md.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
COMPOSE_FILE="$PROJECT_ROOT/docker-compose.test.yml"
RESULTS_DIR="$PROJECT_ROOT/test-results"
TEST_PROJECT_DIR="$PROJECT_ROOT/tests/Azaion.Missions.E2E.Tests"
KEEP_RUNNING=false
for arg in "$@"; do
case "$arg" in
--keep-running) KEEP_RUNNING=true ;;
-h|--help)
cat <<USAGE
Usage: scripts/run-performance-tests.sh [--keep-running]
Runs NFT-PERF-* scenarios from _docs/02_document/tests/performance-tests.md
against the dockerized missions service.
--keep-running Do NOT teardown the docker compose stack on exit (useful
for inspecting timing artifacts).
Thresholds (read from performance-tests.md):
NFT-PERF-01 cascade-delete P50 <= 50ms
NFT-PERF-02 cascade-delete-full P50 <= 200ms (provisional)
NFT-PERF-03 /health P50 <= 10ms
NFT-PERF-04 /missions paginated P95 <= 100ms (provisional)
USAGE
exit 0 ;;
*)
echo "unknown arg: $arg" >&2
exit 64 ;;
esac
done
cleanup() {
local exit_code=$?
if [ "$KEEP_RUNNING" = "true" ]; then
echo "[run-perf] --keep-running set; leaving compose stack up." >&2
else
echo "[run-perf] tearing down compose stack..." >&2
docker compose -f "$COMPOSE_FILE" down -v --remove-orphans >/dev/null 2>&1 || true
fi
exit "$exit_code"
}
trap cleanup EXIT
mkdir -p "$RESULTS_DIR"
## --- Install dependencies ---
command -v docker >/dev/null 2>&1 || {
echo "[run-perf] ERROR: docker is required but not installed on PATH." >&2
exit 2
}
docker compose version >/dev/null 2>&1 || {
echo "[run-perf] ERROR: docker compose v2 plugin is required." >&2
exit 2
}
if [ ! -d "$TEST_PROJECT_DIR" ]; then
cat >&2 <<MSG
[run-perf] WARNING: test project not yet created at:
$TEST_PROJECT_DIR
Performance scenarios are defined in _docs/02_document/tests/performance-tests.md
but no test code exists yet to execute them. Step 6 (Implement Tests) introduces
the [Trait("Category","Perf")] test methods this script invokes.
MSG
exit 0
fi
## --- Start system under test ---
echo "[run-perf] starting compose stack..." >&2
docker compose -f "$COMPOSE_FILE" up -d --build postgres-test missions
echo "[run-perf] waiting for missions /health (timeout 60s)..." >&2
ATTEMPTS=0
until [ "$ATTEMPTS" -ge 60 ]; do
if curl -sf http://localhost:5002/health >/dev/null 2>&1; then
break
fi
ATTEMPTS=$((ATTEMPTS + 1))
sleep 1
done
if [ "$ATTEMPTS" -ge 60 ]; then
echo "[run-perf] ERROR: missions did not become healthy within 60s." >&2
exit 3
fi
## --- Run perf scenarios ---
## The scenarios live in the same xUnit project as the blackbox suite, but are
## tagged [Trait("Category","Perf")] so they only run under this filter. Each
## scenario reports its computed P50/P95 to test-results/perf.csv.
echo "[run-perf] running performance scenarios..." >&2
docker compose -f "$COMPOSE_FILE" --profile test build e2e-consumer
docker compose -f "$COMPOSE_FILE" --profile test run --rm \
-e PERF_RESULTS_FILE=/app/results/perf.csv \
e2e-consumer dotnet test \
/app/Azaion.Missions.E2E.Tests.csproj \
--filter Category=Perf \
--logger "trx;LogFileName=perf.trx"
TEST_EXIT=$?
## --- Compare against thresholds ---
## The xUnit Perf tests already enforce per-scenario thresholds (NFT-PERF-* `Pass
## criteria` in performance-tests.md). A failed assertion -> non-zero TEST_EXIT.
## This script just propagates the verdict; per-scenario detail is in perf.csv.
if [ "$TEST_EXIT" -eq 0 ]; then
echo "[run-perf] ALL THRESHOLDS MET." >&2
if [ -f "$RESULTS_DIR/perf.csv" ]; then
echo "[run-perf] per-scenario detail: $RESULTS_DIR/perf.csv" >&2
fi
else
echo "[run-perf] THRESHOLD FAILURES (exit code $TEST_EXIT)." >&2
echo "[run-perf] missions logs (last 50 lines):" >&2
docker compose -f "$COMPOSE_FILE" logs --tail=50 missions >&2 || true
fi
exit "$TEST_EXIT"