|
| 1 | +# GitHub Actions Port Conflict Fix |
| 2 | + |
| 3 | +## Problem |
| 4 | +GitHub Actions integration tests were failing due to port conflicts. The issue occurred because: |
| 5 | + |
| 6 | +1. GitHub Actions provides PostgreSQL (port 5432) and Redis (port 6379) as services |
| 7 | +2. The test setup code attempted to start its own Docker containers on the same ports |
| 8 | +3. This caused port binding conflicts and test failures |
| 9 | + |
| 10 | +## Solution |
| 11 | +Added environment detection to automatically handle both CI and local development environments: |
| 12 | + |
| 13 | +### Key Changes |
| 14 | + |
| 15 | +1. **Environment Detection** (`tests/integrate/conftest.py`) |
| 16 | + - Added `_detect_github_actions()` method that checks for: |
| 17 | + - `GITHUB_ACTIONS=true` |
| 18 | + - `CI=true` |
| 19 | + - `RUNNER_OS` environment variable |
| 20 | + |
| 21 | +2. **Conditional Container Management** |
| 22 | + - **In GitHub Actions**: Skip Docker container creation, use provided services |
| 23 | + - **In Local Development**: Start Docker containers as before |
| 24 | + |
| 25 | +3. **Updated Cleanup Logic** (`tests/run_tests.sh`) |
| 26 | + - Skip container cleanup in CI environments |
| 27 | + - Preserve normal cleanup in local development |
| 28 | + |
| 29 | +### Testing |
| 30 | +The fix was comprehensively tested with 6 test cases covering: |
| 31 | +- Environment detection in various CI scenarios |
| 32 | +- Container management logic for both environments |
| 33 | +- Proper cleanup behavior |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +### Local Development |
| 38 | +```bash |
| 39 | +# Works as before - containers are started automatically |
| 40 | +make test-integration |
| 41 | +``` |
| 42 | + |
| 43 | +### GitHub Actions |
| 44 | +```yaml |
| 45 | +# No changes needed - detection is automatic |
| 46 | +- name: Run integration tests |
| 47 | + run: python -m pytest tests/integrate/ -v |
| 48 | +``` |
| 49 | +
|
| 50 | +The fix automatically detects the environment and handles container management appropriately, eliminating port conflicts while maintaining compatibility with existing workflows. |
0 commit comments