(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestConcurrentOperations(t *testing.T) { |
| 14 | queue := NewTasksQueue( |
| 15 | "test", |
| 16 | metricsstorage.NewMetricStorage(metricsstorage.WithNewRegistry()), |
| 17 | WithContext(context.Background()), |
| 18 | ) |
| 19 | |
| 20 | // Use a smaller number of goroutines and operations to avoid overwhelming the system |
| 21 | numGoroutines := 10 |
| 22 | opsPerGoroutine := 10 |
| 23 | |
| 24 | var wg sync.WaitGroup |
| 25 | |
| 26 | // 10 goroutines adding tasks |
| 27 | for i := 0; i < numGoroutines; i++ { |
| 28 | wg.Add(1) |
| 29 | go func() { |
| 30 | defer wg.Done() |
| 31 | for j := 0; j < opsPerGoroutine; j++ { |
| 32 | newTask := task.NewTask("test") |
| 33 | queue.AddLast(newTask) |
| 34 | } |
| 35 | }() |
| 36 | } |
| 37 | |
| 38 | // 10 goroutines adding tasks before a random existing task |
| 39 | for i := 0; i < numGoroutines; i++ { |
| 40 | wg.Add(1) |
| 41 | go func() { |
| 42 | defer wg.Done() |
| 43 | for j := 0; j < opsPerGoroutine; j++ { |
| 44 | newTask := task.NewTask("test") |
| 45 | // Try to add before a task that might exist |
| 46 | existingTask := queue.GetFirst() |
| 47 | if existingTask != nil { |
| 48 | queue.AddBefore(existingTask.GetId(), newTask) |
| 49 | } else { |
| 50 | queue.AddLast(newTask) |
| 51 | } |
| 52 | } |
| 53 | }() |
| 54 | } |
| 55 | |
| 56 | // 10 goroutines adding tasks after a random existing task |
| 57 | for i := 0; i < numGoroutines; i++ { |
| 58 | wg.Add(1) |
| 59 | go func() { |
| 60 | defer wg.Done() |
| 61 | for j := 0; j < opsPerGoroutine; j++ { |
| 62 | newTask := task.NewTask("test") |
| 63 | // Try to add after a task that might exist |
| 64 | existingTask := queue.GetFirst() |
| 65 | if existingTask != nil { |
| 66 | queue.AddAfter(existingTask.GetId(), newTask) |
| 67 | } else { |
| 68 | queue.AddLast(newTask) |
| 69 | } |
| 70 | } |
nothing calls this directly
no test coverage detected