92dffe8c60
- Enhanced CI/CD pipeline with coverage reporting, benchmarks, and artifact uploads - Implemented rate limiter IP validation with proxy support and spoofing protection - Added extensive Makefile test targets for coverage, benchmarks, and continuous testing - Expanded middleware chain with request validation, size limits, and suspicious activity logging
56 lines
2.2 KiB
Bash
Executable File
56 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Validation Script for Goroutine Leak Fix
|
|
# Tests that the rate limiter properly shuts down without leaking goroutines
|
|
|
|
set -e
|
|
|
|
echo "========================================="
|
|
echo "Goroutine Leak Fix Validation"
|
|
echo "========================================="
|
|
echo ""
|
|
|
|
# Test 1: Run unit tests
|
|
echo "Test 1: Running rate limiter unit tests..."
|
|
go test -v -run "TestRateLimiter_" ./internal/middleware/security_test.go ./internal/middleware/security.go ./internal/middleware/csp.go
|
|
echo "✅ All unit tests passed"
|
|
echo ""
|
|
|
|
# Test 2: Race detector
|
|
echo "Test 2: Running tests with race detector..."
|
|
go test -race -run "TestRateLimiter_" ./internal/middleware/security_test.go ./internal/middleware/security.go ./internal/middleware/csp.go
|
|
echo "✅ No race conditions detected"
|
|
echo ""
|
|
|
|
# Test 3: Specific goroutine leak test
|
|
echo "Test 3: Goroutine cleanup validation..."
|
|
go test -v -run "TestRateLimiter_GoroutineCleanup" ./internal/middleware/security_test.go ./internal/middleware/security.go ./internal/middleware/csp.go
|
|
echo "✅ Goroutine cleanup verified"
|
|
echo ""
|
|
|
|
# Test 4: Multiple instances test
|
|
echo "Test 4: Testing multiple rate limiter instances..."
|
|
go test -v -run "TestRateLimiter_NoGoroutineLeakWithManyInstances" ./internal/middleware/security_test.go ./internal/middleware/security.go ./internal/middleware/csp.go
|
|
echo "✅ No leaks with multiple instances"
|
|
echo ""
|
|
|
|
# Test 5: Concurrent shutdown test
|
|
echo "Test 5: Testing concurrent shutdown calls..."
|
|
go test -v -run "TestRateLimiter_ConcurrentShutdowns" ./internal/middleware/security_test.go ./internal/middleware/security.go ./internal/middleware/csp.go
|
|
echo "✅ Concurrent shutdowns handled safely"
|
|
echo ""
|
|
|
|
echo "========================================="
|
|
echo "✅ ALL VALIDATION TESTS PASSED"
|
|
echo "========================================="
|
|
echo ""
|
|
echo "Summary of Fix:"
|
|
echo "- Added quit and done channels for graceful shutdown"
|
|
echo "- Implemented Shutdown() method with context timeout"
|
|
echo "- Protected against concurrent shutdown calls with mutex"
|
|
echo "- Updated cleanup() to listen for quit signal"
|
|
echo "- Integrated shutdown into main.go graceful shutdown sequence"
|
|
echo ""
|
|
echo "Before Fix: Goroutines leaked on every restart"
|
|
echo "After Fix: Goroutines properly cleaned up on shutdown"
|