♻️ refactor: decompose hub connection functions for better testability #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Concurrency & Deadlock Tests | |
env: | |
ACTION_ENVIRONMENT: CI | |
on: | |
# Run on pushes to main branches | |
push: | |
branches: | |
- dev | |
- main | |
# Run on PRs that modify concurrency-critical files | |
pull_request: | |
paths: | |
- 'ship/**/*.go' | |
- 'hub/**/*.go' | |
- 'internal/testing/testhelper/**/*.go' | |
- '**/*_test.go' | |
# Allow manual triggering | |
workflow_dispatch: | |
# Run nightly to catch any intermittent issues | |
schedule: | |
- cron: '0 2 * * *' # 2 AM UTC daily | |
jobs: | |
deadlock-detection: | |
name: Deadlock Detection Tests | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Install go-deadlock dependency | |
run: go mod download github.com/sasha-s/go-deadlock | |
- name: Run Deadlock Detection Tests | |
run: | | |
echo "Running deadlock detection tests with enhanced timeout detection..." | |
go test -race -tags=deadlock -timeout=90s -v ./ship ./hub | |
env: | |
GOMAXPROCS: 4 | |
- name: Verify Deadlock Detection Works | |
run: | | |
echo "Verifying deadlock detection is active..." | |
# Test that deadlock detection is properly configured | |
go test -race -tags=deadlock -timeout=10s -run=TestSetStateTimerDeadlock ./ship | |
stress-testing: | |
name: Stress & Load Tests | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Run Stress Tests | |
run: | | |
echo "Running comprehensive stress tests..." | |
go test -race -tags=stress -timeout=180s ./ship ./hub | |
env: | |
GOMAXPROCS: 4 | |
- name: Run High Contention Tests | |
run: | | |
echo "Running high contention scenarios..." | |
go test -race -timeout=90s -run=".*Stress.*|.*Contention.*|.*Concurrent.*" ./ship ./hub | |
performance-regression: | |
name: Performance Regression Detection | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Run Performance Benchmarks | |
run: | | |
echo "Running performance benchmarks to detect regressions..." | |
go test -bench=BenchmarkSetState -benchtime=1s -count=3 ./ship | |
go test -bench=BenchmarkConnectionForSKI -benchtime=1s -count=3 ./hub | |
go test -bench=BenchmarkNumberPairedServices -benchtime=1s -count=3 ./hub | |
- name: Run Lock Contention Benchmarks | |
run: | | |
echo "Testing lock contention performance..." | |
go test -bench=BenchmarkHighContention -benchtime=500ms ./ship ./hub | |
go test -bench=BenchmarkMixedReadWrite -benchtime=500ms ./hub | |
race-condition-detection: | |
name: Race Condition Detection | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
strategy: | |
matrix: | |
# Test with different GOMAXPROCS to increase chance of detecting races | |
gomaxprocs: [1, 2, 4, 8] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Run Race Detection Tests (GOMAXPROCS=${{ matrix.gomaxprocs }}) | |
run: | | |
echo "Running race detection with GOMAXPROCS=${{ matrix.gomaxprocs }}..." | |
go test -race -timeout=90s -count=3 ./ship ./hub | |
env: | |
GOMAXPROCS: ${{ matrix.gomaxprocs }} | |
- name: Run Specific Race-Prone Tests | |
run: | | |
echo "Running tests targeting known race-prone areas..." | |
go test -race -timeout=90s -run=".*Race.*|.*Concurrent.*|.*Timer.*" ./ship ./hub | |
env: | |
GOMAXPROCS: ${{ matrix.gomaxprocs }} | |
memory-leak-detection: | |
name: Memory Leak Detection | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Run Goroutine Leak Tests | |
run: | | |
echo "Testing for goroutine leaks..." | |
go test -race -timeout=90s -run=".*Leak.*|.*Goroutine.*" ./ship ./hub | |
- name: Run Memory Allocation Tests | |
run: | | |
echo "Testing memory allocation patterns..." | |
go test -bench=BenchmarkMemoryAllocation -benchmem ./ship ./hub | |
integration-validation: | |
name: Integration Validation | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
needs: [deadlock-detection, race-condition-detection] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ^1.23 | |
- name: Run Full Integration Tests | |
run: | | |
echo "Running full integration tests with all concurrency features..." | |
go test -race -tags=stress -timeout=120s ./ship ./hub | |
- name: Validate Lock Ordering | |
run: | | |
echo "Validating lock ordering compliance..." | |
go test -race -timeout=90s -run=".*Lock.*Order.*|.*Mutex.*Order.*" ./hub | |
- name: System Health Check | |
run: | | |
echo "Running system health validation..." | |
go test -race -timeout=90s -run=".*System.*|.*Health.*" ./ship ./hub | |
report-results: | |
name: Report Test Results | |
runs-on: ubuntu-latest | |
needs: [deadlock-detection, stress-testing, performance-regression, race-condition-detection, memory-leak-detection, integration-validation] | |
if: always() | |
steps: | |
- name: Report Success | |
if: needs.deadlock-detection.result == 'success' && needs.stress-testing.result == 'success' && needs.race-condition-detection.result == 'success' | |
run: | | |
echo "✅ All concurrency tests passed successfully!" | |
echo "- Deadlock detection: ✅ PASSED" | |
echo "- Stress testing: ✅ PASSED" | |
echo "- Race condition detection: ✅ PASSED" | |
echo "- Memory leak detection: ✅ PASSED" | |
echo "- Integration validation: ✅ PASSED" | |
- name: Report Failures | |
if: needs.deadlock-detection.result == 'failure' || needs.stress-testing.result == 'failure' || needs.race-condition-detection.result == 'failure' | |
run: | | |
echo "❌ Some concurrency tests failed!" | |
echo "- Deadlock detection: ${{ needs.deadlock-detection.result }}" | |
echo "- Stress testing: ${{ needs.stress-testing.result }}" | |
echo "- Race condition detection: ${{ needs.race-condition-detection.result }}" | |
echo "- Memory leak detection: ${{ needs.memory-leak-detection.result }}" | |
echo "- Integration validation: ${{ needs.integration-validation.result }}" | |
echo "" | |
echo "Please review the test logs and address any concurrency issues." | |
exit 1 |