#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" API_URL="${API_URL:-http://localhost:18980}" cleanup() { echo "Cleaning up..." } trap cleanup EXIT echo "=== Satellite Provider Performance Tests ===" echo "API URL: $API_URL" echo "" PASS=0 FAIL=0 check_threshold() { local test_name="$1" local actual_ms="$2" local threshold_ms="$3" if (( actual_ms <= threshold_ms )); then echo " ✓ $test_name: ${actual_ms}ms (threshold: ${threshold_ms}ms)" PASS=$((PASS + 1)) else echo " ✗ $test_name: ${actual_ms}ms EXCEEDS threshold ${threshold_ms}ms" FAIL=$((FAIL + 1)) fi } echo "PT-02: Cached Tile Retrieval Latency (threshold: 500ms)" START=$(date +%s%N) HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$API_URL/api/satellite/tiles/latlon?Latitude=47.461747&Longitude=37.647063&ZoomLevel=18") END=$(date +%s%N) ELAPSED_MS=$(( (END - START) / 1000000 )) if [[ "$HTTP_CODE" == "200" ]]; then check_threshold "Cached tile retrieval" "$ELAPSED_MS" 500 else echo " ✗ PT-02: HTTP $HTTP_CODE (expected 200) - tile may not be cached yet" FAIL=$((FAIL + 1)) fi echo "" echo "PT-06: Route Point Interpolation Speed (threshold: 5000ms)" ROUTE_ID=$(uuidgen | tr '[:upper:]' '[:lower:]') BODY="{\"id\":\"$ROUTE_ID\",\"name\":\"Perf Test\",\"regionSizeMeters\":300,\"zoomLevel\":18,\"points\":[{\"lat\":48.276067,\"lon\":37.384458},{\"lat\":48.270740,\"lon\":37.374029}]}" START=$(date +%s%N) HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" -d "$BODY" "$API_URL/api/satellite/route") END=$(date +%s%N) ELAPSED_MS=$(( (END - START) / 1000000 )) if [[ "$HTTP_CODE" == "200" ]]; then check_threshold "Route creation (2 points)" "$ELAPSED_MS" 5000 else echo " ✗ PT-06: HTTP $HTTP_CODE (expected 200)" FAIL=$((FAIL + 1)) fi echo "" echo "=== Performance Test Summary ===" echo " Passed: $PASS" echo " Failed: $FAIL" echo "" if [[ $FAIL -gt 0 ]]; then echo "FAILED: $FAIL performance threshold(s) exceeded" exit 1 fi echo "ALL PERFORMANCE TESTS PASSED" exit 0