Added nohup in CI to ensure server is up before proceeding to E2E test
This commit is contained in:
parent
8d2ceebade
commit
34605c12b2
|
|
@ -125,14 +125,49 @@ jobs:
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- name: "Start FastAPI Backend Server"
|
||||||
|
env:
|
||||||
|
DATABASE_URL: postgresql://atb:atb_ci_test_password@localhost:5432/atb
|
||||||
|
PYTHONPATH: ${{ github.workspace }}/project_code
|
||||||
|
USE_IDENTITY_MOCK: "True"
|
||||||
|
run: |
|
||||||
|
nohup python3 -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 </dev/null >/tmp/uvicorn.log 2>&1 &
|
||||||
|
for i in {1..30}; do
|
||||||
|
if curl -s http://127.0.0.1:8000/health | grep -q "healthy"; then
|
||||||
|
echo "FastAPI backend server is healthy on port 8000!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "Waiting for backend server to start ($i/30)..."
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if ! curl -s http://127.0.0.1:8000/health | grep -q "healthy"; then
|
||||||
|
echo "Error: Backend server failed to start within 30s. Server logs:"
|
||||||
|
cat /tmp/uvicorn.log
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: "Run Live E2E Integration Test Suite"
|
- name: "Run Live E2E Integration Test Suite"
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: postgresql://atb:atb_ci_test_password@localhost:5432/atb
|
DATABASE_URL: postgresql://atb:atb_ci_test_password@localhost:5432/atb
|
||||||
PYTHONPATH: ${{ github.workspace }}/project_code
|
PYTHONPATH: ${{ github.workspace }}/project_code
|
||||||
USE_IDENTITY_MOCK: "True"
|
USE_IDENTITY_MOCK: "True"
|
||||||
run: |
|
run: |
|
||||||
|
if ! curl -s http://127.0.0.1:8000/health | grep -q "healthy"; then
|
||||||
|
echo "Backend not responding on port 8000, launching server..."
|
||||||
|
nohup python3 -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 </dev/null >/tmp/uvicorn.log 2>&1 &
|
||||||
|
sleep 3
|
||||||
|
fi
|
||||||
python3 -m unittest discover -s project_code/tests/e2e -p "test_*.py"
|
python3 -m unittest discover -s project_code/tests/e2e -p "test_*.py"
|
||||||
|
|
||||||
|
- name: "Dump Server Logs on Failure"
|
||||||
|
if: failure()
|
||||||
|
run: |
|
||||||
|
if [ -f /tmp/uvicorn.log ]; then
|
||||||
|
echo "=== Uvicorn Server Logs ==="
|
||||||
|
cat /tmp/uvicorn.log
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# 4. Multi-Stage Docker Build & Container Image Packaging
|
# 4. Multi-Stage Docker Build & Container Image Packaging
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
|
||||||
|
|
@ -222,3 +222,24 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Turn 12: 2026-10-13T14:25:00Z
|
||||||
|
- **User:**
|
||||||
|
Reported that in Step 3 of CI ("Migrations & Live Container E2E"), after resolving the psycopg driver issue, multiple `ConnectionRefusedError: [Errno 111] Connection refused` errors occurred when running `python3 -m unittest discover -s project_code/tests/e2e -p "test_*.py"`.
|
||||||
|
- **Agent Analysis & Implementation:**
|
||||||
|
- **Root Cause Diagnosis:**
|
||||||
|
- Six live E2E test suites (`test_live_alerts_reporting_e2e.py`, `test_live_api_endpoints.py`, `test_live_finance_settlement_e2e.py`, `test_live_mandi_pipeline_e2e.py`, `test_live_master_data_policies_e2e.py`, `test_live_warehouse_sales_dispatch_e2e.py`) make HTTP requests to `BASE_URL = "http://127.0.0.1:8000"`, verifying `/health` and interacting with API routes.
|
||||||
|
- In `.github/workflows/ci.yml`, the `database-migrations-and-e2e` job spun up PostgreSQL 17 on port 5432 and ran Alembic migrations, but never started the FastAPI backend server (`uvicorn`) prior to executing the E2E test runner.
|
||||||
|
- Consequently, attempts by `urllib.request` to connect to port 8000 failed immediately with `ConnectionRefusedError`.
|
||||||
|
- **Implementation Fixes:**
|
||||||
|
1. In `.github/workflows/ci.yml`:
|
||||||
|
- Inserted the `"Start FastAPI Backend Server"` step before the E2E test execution.
|
||||||
|
- Configured background startup via `nohup python3 -m uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 </dev/null >/tmp/uvicorn.log 2>&1 &` with a 30-second health check polling loop against `http://127.0.0.1:8000/health`.
|
||||||
|
- Added a fallback daemon verification inside the `"Run Live E2E Integration Test Suite"` step to ensure port 8000 remains active across runner subshells.
|
||||||
|
- Added a `"Dump Server Logs on Failure"` step (`if: failure()`) that outputs `/tmp/uvicorn.log` if any test fails, simplifying debugging.
|
||||||
|
- **Verification:**
|
||||||
|
- Verified `.github/workflows/ci.yml` YAML syntax via `yaml.safe_load()`.
|
||||||
|
- Executed `python3 project_code/tests/run_all_tests.py`: 197/197 passing, 98.4% statement coverage.
|
||||||
|
- Executed `python3 scripts/verify_traceability_gates.py --all`: Gates 5.1, 9.1, and 14.1 all PASSED with 0 issues.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue