TestWaitMultipleWaiters tests that multiple waiters can be unblocked by a single tick
()
| 53 | |
| 54 | // TestWaitMultipleWaiters tests that multiple waiters can be unblocked by a single tick |
| 55 | func (s *TestCondSuite) TestWaitMultipleWaiters() { |
| 56 | const numWaiters = 10 |
| 57 | |
| 58 | var wg sync.WaitGroup |
| 59 | var startWg sync.WaitGroup |
| 60 | results := make([]bool, numWaiters) |
| 61 | |
| 62 | // Capture cursor before starting waiters |
| 63 | cursor := s.cond.Cursor() |
| 64 | |
| 65 | // Start multiple waiters |
| 66 | for i := range numWaiters { |
| 67 | wg.Add(1) |
| 68 | startWg.Add(1) |
| 69 | go func(index int) { |
| 70 | defer wg.Done() |
| 71 | startWg.Done() // Signal that this goroutine is ready |
| 72 | s.cond.Wait(cursor) |
| 73 | results[index] = true |
| 74 | }(i) |
| 75 | } |
| 76 | |
| 77 | // Wait for all goroutines to start waiting |
| 78 | startWg.Wait() |
| 79 | |
| 80 | // Wait for all waiters to complete |
| 81 | var done atomic.Bool |
| 82 | go func() { |
| 83 | s.cond.Tick() // Signal that execution can proceed |
| 84 | wg.Wait() |
| 85 | done.Store(true) |
| 86 | }() |
| 87 | |
| 88 | s.Require().Eventually(done.Load, 200*time.Millisecond, 10*time.Millisecond) |
| 89 | |
| 90 | // Check that all waiters were unblocked |
| 91 | for _, completed := range results { |
| 92 | s.Require().True(completed) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // TestClose tests the behavior of the Cond when closed |
| 97 | func (s *TestCondSuite) TestClose() { |