TestBasicWaitAndTick tests the basic functionality of the Cond
()
| 29 | |
| 30 | // TestBasicWaitAndTick tests the basic functionality of the Cond |
| 31 | func (s *TestCondSuite) TestBasicWaitAndTick() { |
| 32 | ch := asyncbuffer.CondCh(s.cond) |
| 33 | |
| 34 | // Start a goroutine that will tick after a short delay |
| 35 | go func() { |
| 36 | time.Sleep(50 * time.Millisecond) |
| 37 | s.cond.Tick() |
| 38 | }() |
| 39 | |
| 40 | // Start a goroutine that will wait for the tick |
| 41 | var done atomic.Bool |
| 42 | go func() { |
| 43 | cursor := s.cond.Cursor() |
| 44 | s.cond.Wait(cursor) |
| 45 | done.Store(true) |
| 46 | }() |
| 47 | |
| 48 | s.Require().Eventually(done.Load, 200*time.Millisecond, 10*time.Millisecond) |
| 49 | |
| 50 | // Means that and old channel was closed and a new one has been created |
| 51 | s.Require().NotEqual(ch, asyncbuffer.CondCh(s.cond)) |
| 52 | } |
| 53 | |
| 54 | // TestWaitMultipleWaiters tests that multiple waiters can be unblocked by a single tick |
| 55 | func (s *TestCondSuite) TestWaitMultipleWaiters() { |