MCPcopy
hub / github.com/kopia/kopia / TestTimerChannelBehavior

Function TestTimerChannelBehavior

internal/sleepable/sleepable_timer_test.go:193–225  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

191}
192
193func TestTimerChannelBehavior(t *testing.T) {
194 // Set a small MaxSleepTime for testing
195 setMaxSleepTimeForTest(t, testMaxSleepTime)
196
197 t.Run("channel closed only once", func(t *testing.T) {
198 start := clock.Now()
199 target := start.Add(10 * time.Millisecond)
200 timer := NewTimer(clock.Now, target)
201 <-timer.C
202 <-timer.C
203 <-timer.C
204
205 select {
206 case <-timer.C:
207 default:
208 t.Error("timer channel should remain closed after trigger")
209 }
210 })
211
212 t.Run("stopped timer channel not closed", func(t *testing.T) {
213 start := clock.Now()
214 target := start.Add(100 * time.Millisecond)
215 timer := NewTimer(clock.Now, target)
216 timer.Stop()
217 time.Sleep(20 * time.Millisecond)
218
219 select {
220 case <-timer.C:
221 t.Error("stopped timer channel should not be closed")
222 default:
223 }
224 })
225}

Callers

nothing calls this directly

Calls 7

StopMethod · 0.95
NowFunction · 0.92
setMaxSleepTimeForTestFunction · 0.85
NewTimerFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected