From e75597427303a8f8261a1b5e1ed29957a4d34557 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Mon, 2 Nov 2026 18:29:41 +0700 Subject: [PATCH] fix(ci): dial the postgres service instead of job loopback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Интеграционные тесты ходили на 127.0.0.1 внутри контейнера job и сразу получали connection refused. DSN указывает на сервис postgres, скрипт ждёт открытия TCP до 90 секунд. Co-authored-by: Cursor --- .gitea/workflows/quality.yaml | 4 +++- scripts/ci/postgres-integration.sh | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/quality.yaml b/.gitea/workflows/quality.yaml index ec78133..abbb86e 100644 --- a/.gitea/workflows/quality.yaml +++ b/.gitea/workflows/quality.yaml @@ -361,7 +361,9 @@ jobs: - name: Run migrations and verify PostgreSQL integration tests executed env: GOFLAGS: -mod=readonly - EVOBGP_TEST_DATABASE_URL: postgres://evobgp:evobgp_ci@127.0.0.1:5432/evobgp_test?sslmode=disable + # Job and the postgres service are sibling containers on act_runner. + # 127.0.0.1 is the job itself; the service is reachable by its name. + EVOBGP_TEST_DATABASE_URL: postgres://evobgp:evobgp_ci@postgres:5432/evobgp_test?sslmode=disable run: bash scripts/ci/postgres-integration.sh legacy-compatibility: diff --git a/scripts/ci/postgres-integration.sh b/scripts/ci/postgres-integration.sh index 86c8344..a92a6fc 100644 --- a/scripts/ci/postgres-integration.sh +++ b/scripts/ci/postgres-integration.sh @@ -3,6 +3,31 @@ set -euo pipefail : "${EVOBGP_TEST_DATABASE_URL:?PostgreSQL integration tests require EVOBGP_TEST_DATABASE_URL}" +# The Gitea job container does not publish the service onto its own loopback. +# Wait until the DSN host accepts TCP so a slow postmaster is not a test failure. +python3 - <<'PY' +import os +import socket +import time +from urllib.parse import urlparse + +raw = os.environ["EVOBGP_TEST_DATABASE_URL"] +parsed = urlparse(raw) +host = parsed.hostname or "127.0.0.1" +port = parsed.port or 5432 +deadline = time.time() + 90 +last = "no attempt" +while time.time() < deadline: + try: + with socket.create_connection((host, port), timeout=2): + print(f"postgres tcp open at {host}:{port}", flush=True) + raise SystemExit(0) + except OSError as exc: + last = str(exc) + time.sleep(2) +raise SystemExit(f"postgres not accepting TCP at {host}:{port} after 90s: {last}") +PY + assert_passes() { local result_file="$1" package="$2" label="$3" shift 3