Clear race conditions

This commit is contained in:
2025-09-06 10:38:32 +01:00
parent a34488f533
commit bf6ab31c50
4 changed files with 97 additions and 39 deletions
+5 -2
View File
@@ -143,7 +143,8 @@ func TestBackgroundTaskCircuitBreaker_SingletonPattern(t *testing.T) {
// Simulate multiple attempts to start cleanup tasks (like from different middleware instances)
var wg sync.WaitGroup
tasks := make([]*BackgroundTask, 0, numAttempts)
tasks := make([]*BackgroundTask, numAttempts)
var tasksMu sync.Mutex
for i := 0; i < numAttempts; i++ {
wg.Add(1)
@@ -175,7 +176,9 @@ func TestBackgroundTaskCircuitBreaker_SingletonPattern(t *testing.T) {
// Here we test that even if multiple start, resource usage is controlled
task.Start()
tasks = append(tasks, task)
tasksMu.Lock()
tasks[id] = task
tasksMu.Unlock()
}(i)
}