From 00bdb5d6d1e0d0f9be3ab1a9208c846a56ca4c48 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Fri, 24 Jul 2026 17:09:03 +0900 Subject: [PATCH] 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 --- .gitea/workflows/ci.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 5bd8f40c..d6aa63d9 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -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