From edda3a5b23e9c06b5df631d6a41ce0c4bf60ebd0 Mon Sep 17 00:00:00 2001 From: ogt Date: Wed, 15 Jul 2026 07:12:14 +0800 Subject: [PATCH] fix(ci): wait for final B5 database readiness --- .gitea/workflows/cd.yaml | 23 ++++++++++++++++++- .../test_cd_b5_database_readiness_gate.py | 18 +++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 apps/api/tests/test_cd_b5_database_readiness_gate.py diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index d1c042925..58ac9ab42 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -1246,7 +1246,9 @@ jobs: pgvector/pgvector:pg16 B5_DB_READY=0 for i in $(seq 1 30); do - if docker exec "$B5_DB_CONTAINER" pg_isready -U awoooi -d awoooi_test; then + if docker logs "$B5_DB_CONTAINER" 2>&1 \ + | grep -Fq 'PostgreSQL init process complete; ready for start up.' \ + && docker exec "$B5_DB_CONTAINER" pg_isready -U awoooi -d awoooi_test; then B5_DB_READY=1 break fi @@ -1266,6 +1268,25 @@ jobs: apt-get install -y -q postgresql-client fi B5_DB_HOST="${B5_DB_HOST:-pg-test-b5}" + # The outer pg_isready can observe the image's temporary init + # postmaster. Verify readiness again from the exact client network + # and process used by setup/tests so the final restart cannot race. + B5_CLIENT_READY=0 + for i in $(seq 1 30); do + if PGPASSWORD=awoooi_test_2026 psql \ + -h "$B5_DB_HOST" -p 5432 -U awoooi -d awoooi_test \ + -v ON_ERROR_STOP=1 -Atqc 'SELECT 1' 2>/dev/null \ + | grep -qx '1'; then + B5_CLIENT_READY=1 + break + fi + sleep 2 + done + if [ "$B5_CLIENT_READY" != "1" ]; then + echo "BLOCKER b5_pg_test_client_network_not_ready" + echo "NEXT_ACTION inspect_b5_final_postmaster_and_test_network_then_retry_cd" + exit 67 + fi # 初始化 schema PGPASSWORD=awoooi_test_2026 psql \ -h "$B5_DB_HOST" -p 5432 -U awoooi -d awoooi_test \ diff --git a/apps/api/tests/test_cd_b5_database_readiness_gate.py b/apps/api/tests/test_cd_b5_database_readiness_gate.py new file mode 100644 index 000000000..efacddd85 --- /dev/null +++ b/apps/api/tests/test_cd_b5_database_readiness_gate.py @@ -0,0 +1,18 @@ +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[3] +CD_WORKFLOW = ROOT / ".gitea" / "workflows" / "cd.yaml" + + +def test_b5_waits_for_final_postmaster_and_same_network_client() -> None: + workflow = CD_WORKFLOW.read_text(encoding="utf-8") + b5 = workflow.split("- name: Integration Tests (B5 — 真實 DB)", 1)[1] + b5 = b5.split("- name: Clean Test Workspace Artifacts", 1)[0] + + assert "PostgreSQL init process complete; ready for start up." in b5 + assert 'B5_CLIENT_READY=0' in b5 + assert "-v ON_ERROR_STOP=1 -Atqc 'SELECT 1'" in b5 + assert "b5_pg_test_client_network_not_ready" in b5 + assert "inspect_b5_final_postmaster_and_test_network_then_retry_cd" in b5 + assert b5.index("B5_CLIENT_READY=0") < b5.index("setup_test_schema.sql")