| 105 | } |
| 106 | |
| 107 | func (s *TestCondSuite) TestRapidTicksAndWaits() { |
| 108 | const iterations = 1000 |
| 109 | |
| 110 | var wg sync.WaitGroup |
| 111 | |
| 112 | // Start a goroutine that will rapidly tick |
| 113 | wg.Go(func() { |
| 114 | timeTicker := time.Tick(time.Microsecond) |
| 115 | |
| 116 | for range iterations { |
| 117 | <-timeTicker |
| 118 | s.cond.Tick() |
| 119 | } |
| 120 | |
| 121 | s.cond.Close() // Close after all ticks |
| 122 | }) |
| 123 | |
| 124 | // Start multiple waiters |
| 125 | for range 10 { |
| 126 | wg.Go(func() { |
| 127 | cursor := s.cond.Cursor() |
| 128 | for range iterations / 10 { |
| 129 | cursor = s.cond.Wait(cursor) |
| 130 | } |
| 131 | }) |
| 132 | } |
| 133 | |
| 134 | var done atomic.Bool |
| 135 | go func() { |
| 136 | wg.Wait() |
| 137 | done.Store(true) |
| 138 | }() |
| 139 | |
| 140 | s.Require().Eventually(done.Load, 200*time.Millisecond, 10*time.Millisecond) |
| 141 | } |
| 142 | |
| 143 | func TestCond(t *testing.T) { |
| 144 | suite.Run(t, new(TestCondSuite)) |