fix: remove t.Parallel() from metrics tests to fix race conditions
All checks were successful
CI / Test (pull_request) Successful in 22s
CI / Lint (pull_request) Successful in 17s
CI / Build (pull_request) Successful in 12s
CI / Format Check (pull_request) Successful in 2s

The Gin framework uses a global mode setting (gin.SetMode()) which is not
thread-safe when tests run in parallel. Removing t.Parallel() from metrics
tests that use gin.SetMode() prevents data races when running tests with
the race detector enabled.

All tests now pass with 'make test' which includes -race flag.
This commit is contained in:
2025-11-05 21:16:45 +01:00
parent 3bc37dd48c
commit a21ea039eb

View File

@@ -34,13 +34,10 @@ func TestNewMetrics(t *testing.T) {
} }
func TestMetrics_HTTPMiddleware(t *testing.T) { func TestMetrics_HTTPMiddleware(t *testing.T) {
t.Parallel() gin.SetMode(gin.TestMode)
metrics := NewMetrics() metrics := NewMetrics()
// Set Gin to test mode
gin.SetMode(gin.TestMode)
router := gin.New() router := gin.New()
router.Use(metrics.HTTPMiddleware()) router.Use(metrics.HTTPMiddleware())
@@ -63,12 +60,10 @@ func TestMetrics_HTTPMiddleware(t *testing.T) {
} }
func TestMetrics_HTTPMiddleware_Error(t *testing.T) { func TestMetrics_HTTPMiddleware_Error(t *testing.T) {
t.Parallel() gin.SetMode(gin.TestMode)
metrics := NewMetrics() metrics := NewMetrics()
gin.SetMode(gin.TestMode)
router := gin.New() router := gin.New()
router.Use(metrics.HTTPMiddleware()) router.Use(metrics.HTTPMiddleware())
@@ -87,8 +82,6 @@ func TestMetrics_HTTPMiddleware_Error(t *testing.T) {
} }
func TestMetrics_Handler(t *testing.T) { func TestMetrics_Handler(t *testing.T) {
t.Parallel()
metrics := NewMetrics() metrics := NewMetrics()
handler := metrics.Handler() handler := metrics.Handler()