TestStopUnblocksAllWaiters verifies that calling Stop on an empty queue unblocks all goroutines waiting in Dequeue, returning zero values.
(t *testing.T)
| 214 | // TestStopUnblocksAllWaiters verifies that calling Stop on an empty queue |
| 215 | // unblocks all goroutines waiting in Dequeue, returning zero values. |
| 216 | func TestStopUnblocksAllWaiters(t *testing.T) { |
| 217 | q := New[mockOp](nil) |
| 218 | numWorkers := 5 |
| 219 | |
| 220 | var allStarted sync.WaitGroup |
| 221 | allStarted.Add(numWorkers) |
| 222 | |
| 223 | var workers sync.WaitGroup |
| 224 | for i := range numWorkers { |
| 225 | workers.Add(1) |
| 226 | go func() { |
| 227 | defer workers.Done() |
| 228 | allStarted.Done() |
| 229 | op := q.Dequeue() |
| 230 | assert.Equal(t, mockOp{}, op, "worker %d: expected zero value from closed queue", i) |
| 231 | }() |
| 232 | } |
| 233 | |
| 234 | allStarted.Wait() |
| 235 | q.Stop() |
| 236 | workers.Wait() |
| 237 | } |