Files
foxhunt/run_smoke_tests.sh
jgrusewski 94cf3bc135 test: Add end-to-end smoke tests (Agent 99)
- Create comprehensive smoke test suite for post-deployment validation
- Implement 4 test categories: infrastructure, service, authentication, order flow
- Add graceful failure handling for unavailable services
- Create automated test runner script with multiple modes (fast, verbose, category)
- Document known blockers from Agent 96 (Backtesting/ML services)
- Add 30+ individual smoke tests covering critical paths
- Enable smoke-tests feature in tests/Cargo.toml
- Create detailed README with usage and troubleshooting

Test Categories:
1. Infrastructure Health: PostgreSQL, Redis, Vault, InfluxDB, Prometheus, Grafana
2. Service Health: Trading Service, API Gateway (+ blocked: Backtesting, ML)
3. Authentication Flow: JWT, sessions, revocation, rate limiting
4. Basic Order Flow: Order CRUD, positions, order history

Features:
- Configurable timeouts (5-10s per test)
- Environment variable configuration
- Graceful service unavailability handling
- Parallel and sequential execution modes
- Detailed pass/fail reporting

Usage:
  ./run_smoke_tests.sh              # Run all tests
  ./run_smoke_tests.sh --fast       # Critical tests only
  ./run_smoke_tests.sh --verbose    # Debug logging
  ./run_smoke_tests.sh --category infrastructure

Blocked Tests (marked with #[ignore]):
- Backtesting Service (config issues from Agent 96)
- ML Training Service (config issues from Agent 96)

Wave 125 Phase 3B - Deployment Excellence
2025-10-07 20:56:34 +02:00

219 lines
7.7 KiB
Bash
Executable File

#!/bin/bash
# Foxhunt HFT System - Automated Smoke Test Suite
# Version: 1.0.0
# Purpose: Validate complete system functionality after deployment
#
# Usage:
# ./run_smoke_tests.sh # Run all smoke tests
# ./run_smoke_tests.sh --fast # Run only critical tests
# ./run_smoke_tests.sh --verbose # Run with detailed logging
# ./run_smoke_tests.sh --category infrastructure # Run specific category
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
VERBOSE=false
FAST_MODE=false
CATEGORY=""
RUST_LOG="${RUST_LOG:-info}"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--verbose|-v)
VERBOSE=true
RUST_LOG="debug"
shift
;;
--fast|-f)
FAST_MODE=true
shift
;;
--category|-c)
CATEGORY="$2"
shift 2
;;
--help|-h)
echo "Foxhunt HFT System - Smoke Test Runner"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --verbose, -v Enable verbose logging (RUST_LOG=debug)"
echo " --fast, -f Run only critical tests (faster execution)"
echo " --category, -c CAT Run specific category only"
echo " Categories: infrastructure, service, authentication, order_flow"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run all smoke tests"
echo " $0 --fast # Run only critical tests"
echo " $0 --verbose # Run with debug logging"
echo " $0 --category infrastructure # Run infrastructure tests only"
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Export environment variables
export RUST_LOG
export DATABASE_URL="${DATABASE_URL:-postgresql://foxhunt:foxhunt_dev_password@localhost:5432/foxhunt}"
export REDIS_URL="${REDIS_URL:-redis://localhost:6379}"
export VAULT_ADDR="${VAULT_ADDR:-http://localhost:8200}"
export INFLUXDB_URL="${INFLUXDB_URL:-http://localhost:8086}"
export API_GATEWAY_URL="${API_GATEWAY_URL:-http://localhost:50051}"
export TRADING_SERVICE_URL="${TRADING_SERVICE_URL:-http://localhost:50052}"
export BACKTESTING_SERVICE_URL="${BACKTESTING_SERVICE_URL:-http://localhost:50053}"
export ML_TRAINING_SERVICE_URL="${ML_TRAINING_SERVICE_URL:-http://localhost:50054}"
export PROMETHEUS_URL="${PROMETHEUS_URL:-http://localhost:9090}"
export GRAFANA_URL="${GRAFANA_URL:-http://localhost:3000}"
export JWT_SECRET="${JWT_SECRET:-dev_secret_key_change_in_production}"
# Print banner
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Foxhunt HFT System - Smoke Test Suite${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Environment info
echo -e "${YELLOW}Environment Configuration:${NC}"
echo " Database: ${DATABASE_URL}"
echo " Redis: ${REDIS_URL}"
echo " Vault: ${VAULT_ADDR}"
echo " API Gateway: ${API_GATEWAY_URL}"
echo " Trading Service: ${TRADING_SERVICE_URL}"
echo " Log Level: ${RUST_LOG}"
if [ "$FAST_MODE" = true ]; then
echo -e " ${GREEN}Mode: FAST (critical tests only)${NC}"
fi
if [ "$CATEGORY" != "" ]; then
echo -e " ${GREEN}Category: ${CATEGORY}${NC}"
fi
echo ""
# Test execution flags
TEST_FLAGS=""
if [ "$VERBOSE" = true ]; then
TEST_FLAGS="-- --nocapture --test-threads=1"
fi
# Function to run a test category
run_test_category() {
local category=$1
local test_name=$2
local description=$3
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}Testing: ${description}${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
if cargo test --test smoke_tests ${test_name} ${TEST_FLAGS}; then
echo ""
echo -e "${GREEN}${description} - PASSED${NC}"
return 0
else
echo ""
echo -e "${RED}${description} - FAILED${NC}"
return 1
fi
}
# Track results
TOTAL_CATEGORIES=0
PASSED_CATEGORIES=0
FAILED_CATEGORIES=0
# Main test execution
echo -e "${YELLOW}🔍 Starting smoke test execution...${NC}"
echo ""
# Category 1: Infrastructure Health (CRITICAL)
if [ -z "$CATEGORY" ] || [ "$CATEGORY" = "infrastructure" ]; then
TOTAL_CATEGORIES=$((TOTAL_CATEGORIES + 1))
if run_test_category "infrastructure" "infrastructure_health" "Infrastructure Health"; then
PASSED_CATEGORIES=$((PASSED_CATEGORIES + 1))
else
FAILED_CATEGORIES=$((FAILED_CATEGORIES + 1))
fi
echo ""
fi
# Category 2: Service Health (CRITICAL)
if [ -z "$CATEGORY" ] || [ "$CATEGORY" = "service" ]; then
TOTAL_CATEGORIES=$((TOTAL_CATEGORIES + 1))
if run_test_category "service" "service_health" "Service Health"; then
PASSED_CATEGORIES=$((PASSED_CATEGORIES + 1))
else
FAILED_CATEGORIES=$((FAILED_CATEGORIES + 1))
echo -e "${YELLOW}⚠️ Note: Some services may not be available due to configuration issues${NC}"
fi
echo ""
fi
# Category 3: Authentication Flow (skip in fast mode)
if [ "$FAST_MODE" = false ] && ([ -z "$CATEGORY" ] || [ "$CATEGORY" = "authentication" ]); then
TOTAL_CATEGORIES=$((TOTAL_CATEGORIES + 1))
if run_test_category "authentication" "authentication_flow" "Authentication Flow"; then
PASSED_CATEGORIES=$((PASSED_CATEGORIES + 1))
else
FAILED_CATEGORIES=$((FAILED_CATEGORIES + 1))
fi
echo ""
fi
# Category 4: Basic Order Flow (skip in fast mode)
if [ "$FAST_MODE" = false ] && ([ -z "$CATEGORY" ] || [ "$CATEGORY" = "order_flow" ]); then
TOTAL_CATEGORIES=$((TOTAL_CATEGORIES + 1))
if run_test_category "order_flow" "basic_order_flow" "Basic Order Flow"; then
PASSED_CATEGORIES=$((PASSED_CATEGORIES + 1))
else
FAILED_CATEGORIES=$((FAILED_CATEGORIES + 1))
fi
echo ""
fi
# Print summary
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} Smoke Test Summary${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo " Total Categories: ${TOTAL_CATEGORIES}"
echo -e " ${GREEN}Passed: ${PASSED_CATEGORIES}${NC}"
if [ $FAILED_CATEGORIES -gt 0 ]; then
echo -e " ${RED}Failed: ${FAILED_CATEGORIES}${NC}"
else
echo " Failed: ${FAILED_CATEGORIES}"
fi
echo ""
# Calculate percentage
if [ $TOTAL_CATEGORIES -gt 0 ]; then
PASS_PERCENTAGE=$((PASSED_CATEGORIES * 100 / TOTAL_CATEGORIES))
echo " Pass Rate: ${PASS_PERCENTAGE}%"
echo ""
fi
# Exit with appropriate code
if [ $FAILED_CATEGORIES -eq 0 ]; then
echo -e "${GREEN}✅ All smoke tests passed!${NC}"
echo -e "${GREEN} System is ready for deployment.${NC}"
exit 0
else
echo -e "${YELLOW}⚠️ Some smoke tests failed${NC}"
echo -e "${YELLOW} Review the failures above before deploying.${NC}"
exit 1
fi