fix(ci): wait for final B5 database readiness
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 1s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 1m36s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped

This commit is contained in:
ogt
2026-07-15 07:12:14 +08:00
parent 4b18c2062b
commit edda3a5b23
2 changed files with 40 additions and 1 deletions

View File

@@ -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 \

View File

@@ -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")