fix(ci): stabilize database connection and Python environment
Add PostgreSQL connection retry logic (30 attempts, 2s intervals) to prevent flaky test failures when PostgreSQL service takes time to start. Add Python environment variables: - PYTHONUNBUFFERED: immediate log output (no buffering) - PYTHONDONTWRITEBYTECODE: skip .pyc generation - --no-cache-dir: prevent pip cache issues Fixes intermittent 'connection refused' errors in CI runs. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+20
-3
@@ -13,6 +13,8 @@ concurrency:
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: '9.0.x'
|
||||
PYTHONUNBUFFERED: '1'
|
||||
PYTHONDONTWRITEBYTECODE: '1'
|
||||
|
||||
jobs:
|
||||
# ========================================================================
|
||||
@@ -76,7 +78,7 @@ jobs:
|
||||
run: |
|
||||
# Install from requirements.txt (cache key from setup-python)
|
||||
pip install --disable-pip-version-check --quiet --upgrade pip setuptools wheel
|
||||
pip install --disable-pip-version-check --quiet -r requirements.txt psycopg2-binary
|
||||
pip install --disable-pip-version-check --quiet --no-cache-dir -r requirements.txt psycopg2-binary
|
||||
|
||||
# Verify installation
|
||||
python3 -c 'import requests, yaml, openpyxl, pytest, psycopg; print("✓ Python dependencies installed")'
|
||||
@@ -89,8 +91,23 @@ jobs:
|
||||
run: |
|
||||
which psql || (sudo apt-get update -qq && sudo apt-get install -y -qq postgresql-client)
|
||||
|
||||
echo "=== Database Connection Check ==="
|
||||
psql -U quantengine_ci -d quantenginedb -c "SELECT version();" || exit 1
|
||||
echo "=== Waiting for PostgreSQL to be ready ==="
|
||||
ATTEMPT=0
|
||||
MAX_ATTEMPTS=30
|
||||
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
|
||||
if psql -U quantengine_ci -d quantenginedb -c "SELECT version();" 2>/dev/null; then
|
||||
echo "✓ PostgreSQL is ready"
|
||||
break
|
||||
fi
|
||||
ATTEMPT=$((ATTEMPT + 1))
|
||||
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: PostgreSQL not ready, waiting..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
|
||||
echo "ERROR: PostgreSQL failed to start after $MAX_ATTEMPTS attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=== Applying Migrations ==="
|
||||
for f in $(ls src/dotnet/QuantEngine.Infrastructure/Migrations/V*.sql | sort -V); do
|
||||
|
||||
Reference in New Issue
Block a user