working
This commit is contained in:
parent
c0999370c6
commit
4e1a339432
17 changed files with 393 additions and 91 deletions
|
|
@ -3,13 +3,15 @@ set -e
|
|||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
# E2E tests use a separate database and port to allow parallel execution with backend tests
|
||||
E2E_PORT=${E2E_PORT:-8001}
|
||||
E2E_DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/arbret_e2e"
|
||||
# E2E tests use separate databases and ports per worker for parallel execution
|
||||
E2E_PORT_START=${E2E_PORT_START:-8001}
|
||||
NUM_WORKERS=${NUM_WORKERS:-8} # Default to 8 workers, can be overridden
|
||||
|
||||
# Cleanup function to kill background processes
|
||||
cleanup() {
|
||||
kill $BACKEND_PID 2>/dev/null || true
|
||||
for pid in "${BACKEND_PIDS[@]}"; do
|
||||
kill $pid 2>/dev/null || true
|
||||
done
|
||||
}
|
||||
|
||||
# Ensure cleanup runs on exit (normal, error, or interrupt)
|
||||
|
|
@ -22,42 +24,76 @@ if [ -f .env ]; then
|
|||
set +a
|
||||
fi
|
||||
|
||||
# Kill any existing e2e backend (on our specific port)
|
||||
pkill -f "uvicorn main:app --port $E2E_PORT" 2>/dev/null || true
|
||||
# Kill any existing e2e backends
|
||||
echo "Cleaning up existing e2e backends..."
|
||||
for i in $(seq 0 $((NUM_WORKERS - 1))); do
|
||||
PORT=$((E2E_PORT_START + i))
|
||||
pkill -f "uvicorn main:app --port $PORT" 2>/dev/null || true
|
||||
done
|
||||
sleep 1
|
||||
|
||||
# Seed the e2e database with roles and test users
|
||||
# Seed all worker databases
|
||||
echo "Seeding worker databases..."
|
||||
cd backend
|
||||
echo "Seeding e2e database..."
|
||||
DATABASE_URL="$E2E_DATABASE_URL" uv run python seed.py
|
||||
BACKEND_PIDS=()
|
||||
for i in $(seq 0 $((NUM_WORKERS - 1))); do
|
||||
DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/arbret_e2e_worker$i"
|
||||
echo " Seeding database arbret_e2e_worker$i..."
|
||||
DATABASE_URL="$DATABASE_URL" E2E_MODE=1 uv run python seed.py &
|
||||
done
|
||||
wait
|
||||
cd ..
|
||||
|
||||
# Start backend for e2e tests (uses e2e database and separate port)
|
||||
# Start backends for each worker
|
||||
echo "Starting $NUM_WORKERS backend instances..."
|
||||
cd backend
|
||||
DATABASE_URL="$E2E_DATABASE_URL" uv run uvicorn main:app --port $E2E_PORT --log-level warning &
|
||||
BACKEND_PID=$!
|
||||
for i in $(seq 0 $((NUM_WORKERS - 1))); do
|
||||
PORT=$((E2E_PORT_START + i))
|
||||
DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/arbret_e2e_worker$i"
|
||||
echo " Starting backend on port $PORT for worker $i..."
|
||||
DATABASE_URL="$DATABASE_URL" E2E_MODE=1 uv run uvicorn main:app --port $PORT --log-level warning &
|
||||
BACKEND_PIDS+=($!)
|
||||
done
|
||||
cd ..
|
||||
|
||||
# Wait for backend
|
||||
sleep 2
|
||||
# Wait for all backends to be ready
|
||||
echo "Waiting for backends to be ready..."
|
||||
for i in $(seq 0 $((NUM_WORKERS - 1))); do
|
||||
PORT=$((E2E_PORT_START + i))
|
||||
MAX_ATTEMPTS=30
|
||||
ATTEMPT=0
|
||||
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
|
||||
if curl -s "http://localhost:$PORT/docs" > /dev/null 2>&1; then
|
||||
echo " Backend on port $PORT is ready"
|
||||
break
|
||||
fi
|
||||
ATTEMPT=$((ATTEMPT + 1))
|
||||
sleep 0.5
|
||||
done
|
||||
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
|
||||
echo " ERROR: Backend on port $PORT failed to start"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Generate API types from OpenAPI schema (using e2e backend)
|
||||
# Generate API types from first e2e backend (they should all have same schema)
|
||||
echo "Generating API types from e2e backend..."
|
||||
cd frontend
|
||||
npx openapi-typescript "http://localhost:$E2E_PORT/openapi.json" -o app/generated/api.ts
|
||||
npx openapi-typescript "http://localhost:$E2E_PORT_START/openapi.json" -o app/generated/api.ts
|
||||
cd ..
|
||||
|
||||
# Run tests with e2e-specific backend URL
|
||||
# The frontend will connect to our e2e backend on $E2E_PORT
|
||||
# Tests will determine which backend to use based on worker index
|
||||
cd frontend
|
||||
export NEXT_PUBLIC_API_URL="http://localhost:$E2E_PORT"
|
||||
export NEXT_PUBLIC_API_URL="http://localhost:$E2E_PORT_START" # Default, tests override per worker
|
||||
export E2E_PORT_START=$E2E_PORT_START
|
||||
export NUM_WORKERS=$NUM_WORKERS
|
||||
if [ -n "$1" ]; then
|
||||
NODE_NO_WARNINGS=1 npx playwright test "$1"
|
||||
NODE_NO_WARNINGS=1 npx playwright test --workers=$NUM_WORKERS "$1"
|
||||
else
|
||||
NODE_NO_WARNINGS=1 npm run test:e2e
|
||||
NODE_NO_WARNINGS=1 npx playwright test --workers=$NUM_WORKERS
|
||||
fi
|
||||
EXIT_CODE=$?
|
||||
|
||||
# Cleanup is handled by trap EXIT
|
||||
exit $EXIT_CODE
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue