fix: remove t.Parallel() from server tests to fix race conditions

The Gin framework uses a global mode setting (gin.SetMode()) which is not
thread-safe when tests run in parallel. Removing t.Parallel() from all
server 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:10:06 +01:00
parent 5fdbb729bd
commit 3f3545ba15
2 changed files with 4 additions and 24 deletions

View File

@@ -13,8 +13,6 @@ import (
) )
func TestRequestIDMiddleware(t *testing.T) { func TestRequestIDMiddleware(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
router := gin.New() router := gin.New()
@@ -47,8 +45,6 @@ func TestRequestIDMiddleware(t *testing.T) {
} }
func TestRequestIDMiddleware_ExistingHeader(t *testing.T) { func TestRequestIDMiddleware_ExistingHeader(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
router := gin.New() router := gin.New()
@@ -70,8 +66,6 @@ func TestRequestIDMiddleware_ExistingHeader(t *testing.T) {
} }
func TestLoggingMiddleware(t *testing.T) { func TestLoggingMiddleware(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
mockLogger := &mockLogger{} mockLogger := &mockLogger{}
@@ -99,8 +93,6 @@ func TestLoggingMiddleware(t *testing.T) {
} }
func TestPanicRecoveryMiddleware(t *testing.T) { func TestPanicRecoveryMiddleware(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
mockErrorBus := &mockErrorBusMiddleware{} mockErrorBus := &mockErrorBusMiddleware{}
@@ -128,8 +120,6 @@ func TestPanicRecoveryMiddleware(t *testing.T) {
} }
func TestPanicRecoveryMiddleware_ErrorPanic(t *testing.T) { func TestPanicRecoveryMiddleware_ErrorPanic(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
mockErrorBus := &mockErrorBusMiddleware{} mockErrorBus := &mockErrorBusMiddleware{}
@@ -156,8 +146,6 @@ func TestPanicRecoveryMiddleware_ErrorPanic(t *testing.T) {
} }
func TestCORSMiddleware(t *testing.T) { func TestCORSMiddleware(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
router := gin.New() router := gin.New()
@@ -183,8 +171,6 @@ func TestCORSMiddleware(t *testing.T) {
} }
func TestCORSMiddleware_OPTIONS(t *testing.T) { func TestCORSMiddleware_OPTIONS(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
router := gin.New() router := gin.New()
@@ -205,8 +191,6 @@ func TestCORSMiddleware_OPTIONS(t *testing.T) {
} }
func TestTimeoutMiddleware(t *testing.T) { func TestTimeoutMiddleware(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
router := gin.New() router := gin.New()

View File

@@ -14,7 +14,7 @@ import (
) )
func TestNewServer(t *testing.T) { func TestNewServer(t *testing.T) {
t.Parallel() gin.SetMode(gin.TestMode)
mockConfig := &mockConfigProvider{ mockConfig := &mockConfigProvider{
values: map[string]any{ values: map[string]any{
@@ -51,7 +51,7 @@ func TestNewServer(t *testing.T) {
} }
func TestNewServer_DefaultValues(t *testing.T) { func TestNewServer_DefaultValues(t *testing.T) {
t.Parallel() gin.SetMode(gin.TestMode)
mockConfig := &mockConfigProvider{ mockConfig := &mockConfigProvider{
values: map[string]any{ values: map[string]any{
@@ -76,7 +76,7 @@ func TestNewServer_DefaultValues(t *testing.T) {
} }
func TestServer_Router(t *testing.T) { func TestServer_Router(t *testing.T) {
t.Parallel() gin.SetMode(gin.TestMode)
mockConfig := &mockConfigProvider{ mockConfig := &mockConfigProvider{
values: map[string]any{ values: map[string]any{
@@ -102,7 +102,7 @@ func TestServer_Router(t *testing.T) {
} }
func TestServer_Shutdown(t *testing.T) { func TestServer_Shutdown(t *testing.T) {
t.Parallel() gin.SetMode(gin.TestMode)
mockConfig := &mockConfigProvider{ mockConfig := &mockConfigProvider{
values: map[string]any{ values: map[string]any{
@@ -140,8 +140,6 @@ func TestServer_Shutdown(t *testing.T) {
} }
func TestServer_HealthEndpoints(t *testing.T) { func TestServer_HealthEndpoints(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
mockConfig := &mockConfigProvider{ mockConfig := &mockConfigProvider{
@@ -181,8 +179,6 @@ func TestServer_HealthEndpoints(t *testing.T) {
} }
func TestServer_MetricsEndpoint(t *testing.T) { func TestServer_MetricsEndpoint(t *testing.T) {
t.Parallel()
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
mockConfig := &mockConfigProvider{ mockConfig := &mockConfigProvider{