#!/bin/bash # Parallel Feature Test Runner Script # Runs multiple feature tests in parallel with proper isolation set -e SCRIPTS_DIR=$(dirname `realpath ${BASH_SOURCE[0]}`) cd $SCRIPTS_DIR/.. echo "๐Ÿš€ Parallel Feature Test Runner" echo "================================" echo # Define features and their ports declare -a features=( "auth:9192" "config:9193" "greet:9194" "health:9195" "jwt:9196" ) # Function to run a single feature test run_feature_test() { local feature_port="$1" local feature_name="$2" local port="$3" echo "๐Ÿงช Starting ${feature_name} feature tests on port ${port}..." # Set feature-specific environment variables export DLC_DATABASE_HOST="localhost" export DLC_DATABASE_PORT="5432" export DLC_DATABASE_USER="postgres" export DLC_DATABASE_PASSWORD="postgres" export DLC_DATABASE_NAME="dance_lessons_coach_${feature_name}_test" export DLC_DATABASE_SSL_MODE="disable" # Create feature-specific database using docker if ! docker exec dance-lessons-coach-postgres psql -U postgres -lqt | cut -d \| -f 1 | grep -qw "${DLC_DATABASE_NAME}"; then echo "๐Ÿ“ฆ Creating ${feature_name} test database..." docker exec dance-lessons-coach-postgres createdb -U postgres "${DLC_DATABASE_NAME}" fi # Run the feature tests with tag exclusion cd "features/${feature_name}" FEATURE=${feature_name} DLC_DATABASE_NAME="${DLC_DATABASE_NAME}" go test -v . -tags="~@flaky && ~@todo && ~@skip" 2>&1 | grep -E "(PASS|FAIL|RUN)" || true # Cleanup cd ../.. docker exec dance-lessons-coach-postgres dropdb -U postgres "${DLC_DATABASE_NAME}" 2>/dev/null || true echo "โœ… ${feature_name} feature tests completed" } # Check if PostgreSQL is running if ! docker ps --format '{{.Names}}' | grep -q "^dance-lessons-coach-postgres$"; then echo "โŒ PostgreSQL container is not running. Please start PostgreSQL first." echo "๐Ÿ’ก Try: docker compose up -d postgres" exit 1 fi # Check if PostgreSQL is ready max_attempts=10 attempt=0 while [ $attempt -lt $max_attempts ]; do if docker exec dance-lessons-coach-postgres pg_isready -U postgres 2>/dev/null; then break fi attempt=$((attempt + 1)) sleep 1 done if [ $attempt -eq $max_attempts ]; then echo "โŒ PostgreSQL is not ready. Please check the container logs." exit 1 fi echo "โœ… PostgreSQL is ready for parallel testing" echo # Run feature tests in parallel for feature_port in "${features[@]}"; do # Split feature:port into separate variables IFS=':' read -r feature_name port <<< "${feature_port}" # Run test in background run_feature_test "${feature_port}" "${feature_name}" "${port}" & done # Wait for all background processes to complete wait echo echo "๐ŸŽ‰ All parallel feature tests completed!" echo "๐Ÿ“Š Check individual feature test outputs above for results"