🚀 feat: make random ports default for BDD tests to prevent conflicts
This commit is contained in:
@@ -84,6 +84,72 @@ GODOG_TAGS="@jwt && ~@todo" go test ./features/...
|
||||
DLC_DATABASE_HOST=localhost GODOG_TAGS="@wip" go test ./features/jwt/...
|
||||
```
|
||||
|
||||
### Random Port Selection (Default Behavior)
|
||||
|
||||
By default, BDD tests use **random ports** (10000-19999) to prevent port conflicts during parallel execution. This ensures tests can run reliably in CI/CD pipelines and when executed multiple times.
|
||||
|
||||
**Benefits:**
|
||||
- ✅ No port conflicts in parallel test execution
|
||||
- ✅ Safe for repeated test runs
|
||||
- ✅ Better for CI/CD environments
|
||||
|
||||
**Disable random ports (not recommended):**
|
||||
```bash
|
||||
FIXED_TEST_PORT=true go test ./features/...
|
||||
```
|
||||
|
||||
**Force specific port (debugging only):**
|
||||
```bash
|
||||
# Create a test config file with fixed port
|
||||
echo "server:
|
||||
port: 9191" > test-config.yaml
|
||||
FEATURE=debug FIXED_TEST_PORT=true go test ./features/...
|
||||
```
|
||||
|
||||
### Test Validation Process
|
||||
|
||||
To ensure test suite stability, follow this validation process:
|
||||
|
||||
**Validation Command:**
|
||||
```bash
|
||||
# Clean cache and run all tests 20 times
|
||||
echo "🧪 Validating test suite stability..."
|
||||
for i in {1..20}; do
|
||||
echo "Run $i/20..."
|
||||
go clean -testcache
|
||||
if ! go test ./... > /dev/null 2>&1; then
|
||||
echo "❌ Test run $i failed"
|
||||
go test ./... -v
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "✅ All 20 test runs passed successfully!"
|
||||
```
|
||||
|
||||
**Failure Handling:**
|
||||
- If any test fails during validation, mark it as `@wip` and investigate
|
||||
- Use `@flaky` tag for intermittently failing tests
|
||||
- Document the issue in the test scenario comments
|
||||
|
||||
**Success Criteria:**
|
||||
- ✅ 100% pass rate across 20 consecutive runs
|
||||
- ✅ No undefined/pending steps
|
||||
- ✅ No race conditions or port conflicts
|
||||
- ✅ Consistent execution time
|
||||
|
||||
**CI/CD Integration:**
|
||||
```yaml
|
||||
- name: Validate Test Suite
|
||||
run: |
|
||||
echo "🧪 Running 20 validation runs..."
|
||||
for i in {1..20}; do
|
||||
echo "Run $i/20"
|
||||
go clean -testcache
|
||||
go test ./... || exit 1
|
||||
done
|
||||
echo "✅ Test suite validated successfully"
|
||||
```
|
||||
|
||||
### Stop On Failure Control
|
||||
You can control whether tests stop on first failure using the `GODOG_STOP_ON_FAILURE` environment variable.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user