| 119 | } |
| 120 | |
| 121 | func TestTimerConcurrentStop(t *testing.T) { |
| 122 | // Set a small MaxSleepTime for testing |
| 123 | setMaxSleepTimeForTest(t, testMaxSleepTime) |
| 124 | |
| 125 | t.Run("multiple stops", func(t *testing.T) { |
| 126 | start := clock.Now() |
| 127 | target := start.Add(100 * time.Millisecond) |
| 128 | |
| 129 | timer := NewTimer(clock.Now, target) |
| 130 | |
| 131 | var wg sync.WaitGroup |
| 132 | for range 10 { |
| 133 | wg.Go(timer.Stop) |
| 134 | } |
| 135 | |
| 136 | wg.Wait() |
| 137 | time.Sleep(20 * time.Millisecond) |
| 138 | |
| 139 | select { |
| 140 | case <-timer.C: |
| 141 | t.Error("timer triggered after being stopped") |
| 142 | default: |
| 143 | } |
| 144 | }) |
| 145 | } |
| 146 | |
| 147 | func TestTimerEdgeCases(t *testing.T) { |
| 148 | // Set a small MaxSleepTime for testing |