From 8d47c0c37867aa8c08f3b14351990357484b3649 Mon Sep 17 00:00:00 2001 From: nessi Date: Sun, 15 Feb 2026 20:07:35 +0100 Subject: [PATCH] [NX-501 Issue] Add wait for PostgreSQL in e2e API smoke workflow This change introduces a step in the e2e API smoke workflow to wait for PostgreSQL readiness before executing further steps. It retries the connection multiple times to ensure the database is available, reducing potential errors caused by service unavailability. --- .github/workflows/e2e-api-smoke.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/e2e-api-smoke.yml b/.github/workflows/e2e-api-smoke.yml index e8be1f0..7186a16 100644 --- a/.github/workflows/e2e-api-smoke.yml +++ b/.github/workflows/e2e-api-smoke.yml @@ -68,6 +68,32 @@ jobs: pip install -r backend/requirements.txt pip install pytest + - name: Wait for PostgreSQL service + run: | + python - <<'PY' + import asyncio + import asyncpg + + async def wait_for_db(): + dsn = "postgresql://nexapg:nexapg@127.0.0.1:5432/nexapg?sslmode=disable" + last_err = None + for attempt in range(1, 61): + try: + conn = await asyncpg.connect(dsn=dsn, timeout=3) + try: + await conn.execute("SELECT 1") + finally: + await conn.close() + print(f"PostgreSQL ready after {attempt} attempt(s).") + return + except Exception as exc: + last_err = exc + await asyncio.sleep(2) + raise RuntimeError(f"PostgreSQL not ready after retries: {last_err}") + + asyncio.run(wait_for_db()) + PY + - name: Run Alembic migrations working-directory: backend run: alembic upgrade head