#!/usr/bin/env bash # Performance E2E runner for Azaion.Annotations. # Re-uses the same compose stack as run-tests.sh but flips E2E_RUN_PROFILE=performance, # which causes the xUnit runner to select the NFT-PERF-* test category. # # Threshold values come from _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/e2e/docker-compose.test.yml" RESULTS_DIR="$PROJECT_ROOT/test-results" E2E_RESULTS_DIR="$PROJECT_ROOT/e2e/e2e-results" KEEP_STACK=false for arg in "$@"; do case "$arg" in --keep-stack) KEEP_STACK=true ;; -h|--help) cat </dev/null 2>&1 || true fi } trap cleanup EXIT fixtures_dir="$PROJECT_ROOT/../detections/_docs/00_problem/input_data" if [ ! -d "$fixtures_dir" ]; then echo "[run-performance-tests] FATAL: fixtures dir not found at $fixtures_dir" >&2 exit 2 fi export GIT_SHA="${GIT_SHA:-$(git -C "$PROJECT_ROOT" rev-parse --short HEAD 2>/dev/null || echo local)}" export E2E_RUN_PROFILE=performance echo "[run-performance-tests] profile=$E2E_RUN_PROFILE git_sha=$GIT_SHA" echo "[run-performance-tests] starting compose stack..." docker compose -f "$COMPOSE_FILE" up \ --build \ --abort-on-container-exit \ --exit-code-from e2e-runner # Pass/fail summary: the runner writes a CSV with per-scenario verdict + measured value. report_csv="$E2E_RESULTS_DIR/report.csv" if [ ! -f "$report_csv" ]; then echo "[run-performance-tests] FAIL — runner produced no CSV at $report_csv" >&2 exit 1 fi # Each scenario row: test_id,test_name,category,traces_to,execution_time_ms,result,error_message fail_count=$(awk -F',' 'NR>1 && $6=="FAIL" {n++} END{print n+0}' "$report_csv") pass_count=$(awk -F',' 'NR>1 && $6=="PASS" {n++} END{print n+0}' "$report_csv") total=$((fail_count + pass_count)) echo "[run-performance-tests] $pass_count / $total scenarios met threshold" if [ "$fail_count" -gt 0 ]; then echo "[run-performance-tests] FAIL scenarios:" awk -F',' 'NR>1 && $6=="FAIL" {print " - " $1 " " $2 " (" $7 ")"}' "$report_csv" exit 1 fi echo "[run-performance-tests] PASS — all thresholds met" exit 0