(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestMockClock_NewTicker(t *testing.T) { |
| 32 | var n atomic.Int32 |
| 33 | clock := NewMockClock() |
| 34 | |
| 35 | done := make(chan struct{}) |
| 36 | defer func() { <-done }() // wait for end |
| 37 | |
| 38 | quit := make(chan struct{}) |
| 39 | // Create a channel to increment every microsecond. |
| 40 | go func(ticker *time.Ticker) { |
| 41 | defer close(done) |
| 42 | for { |
| 43 | select { |
| 44 | case <-quit: |
| 45 | ticker.Stop() |
| 46 | return |
| 47 | case <-ticker.C: |
| 48 | n.Add(1) |
| 49 | } |
| 50 | } |
| 51 | }(clock.NewTicker(time.Microsecond)) |
| 52 | |
| 53 | // Move clock forward. |
| 54 | clock.Add(2 * time.Microsecond) |
| 55 | assert.Equal(t, int32(2), n.Load()) |
| 56 | close(quit) |
| 57 | } |
| 58 | |
| 59 | func TestMockClock_NewTicker_slowConsumer(t *testing.T) { |
| 60 | clock := NewMockClock() |
nothing calls this directly
no test coverage detected