diff --git a/scripts/ci/run_integration_tests.sh b/scripts/ci/run_integration_tests.sh index 72ba4dfbe..359f91666 100755 --- a/scripts/ci/run_integration_tests.sh +++ b/scripts/ci/run_integration_tests.sh @@ -44,6 +44,17 @@ for i in $(seq 1 15); do done docker inspect --format='{{.State.Health.Status}}' "$REDIS_CONTAINER" | grep -q healthy +# 额外验证:确保从宿主侧通过映射端口实际能连上 Redis +for i in $(seq 1 20); do + if python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $REDIS_PORT)); s.close()" 2>/dev/null; then + echo "TCP connectivity to Redis confirmed on port $REDIS_PORT" + break + fi + echo "Waiting for TCP connectivity to Redis on port $REDIS_PORT... ($i/20)" + sleep 2 +done +python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $REDIS_PORT)); s.close()" + # --- 启动 PostgreSQL --- echo "" echo "=== 启动 PostgreSQL ===" @@ -73,6 +84,17 @@ for i in $(seq 1 30); do done docker inspect --format='{{.State.Health.Status}}' "$PG_CONTAINER" | grep -q healthy +# 额外验证:确保从宿主侧通过映射端口实际能连上 PG(端口映射可能有延迟) +for i in $(seq 1 30); do + if python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()" 2>/dev/null; then + echo "TCP connectivity to PostgreSQL confirmed on port $PG_PORT" + break + fi + echo "Waiting for TCP connectivity to PostgreSQL on port $PG_PORT... ($i/30)" + sleep 2 +done +python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()" + # --- 执行迁移 --- echo "" echo "=== 执行 Alembic 迁移 ===" diff --git a/scripts/ci/run_validate.sh b/scripts/ci/run_validate.sh index ade0dd049..67476c727 100755 --- a/scripts/ci/run_validate.sh +++ b/scripts/ci/run_validate.sh @@ -196,6 +196,18 @@ for i in $(seq 1 30); do sleep 2 done docker inspect --format='{{.State.Health.Status}}' "$PG_CONTAINER" | grep -q healthy + +# 额外验证:确保从宿主侧通过映射端口实际能连上(端口映射可能有延迟) +for i in $(seq 1 30); do + if python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()" 2>/dev/null; then + echo "TCP connectivity to PostgreSQL confirmed on port $PG_PORT" + break + fi + echo "Waiting for TCP connectivity to PostgreSQL on port $PG_PORT... ($i/30)" + sleep 2 +done +python3 -c "import socket; s=socket.socket(); s.settimeout(2); s.connect(('127.0.0.1', $PG_PORT)); s.close()" + PYTHONPATH="$PWD/apps/api:$PWD" python3 -m alembic upgrade head echo "✅ Alembic migrations applied successfully" docker rm -f "$PG_CONTAINER" 2>/dev/null || true