MCPcopy
hub / github.com/kopia/kopia / TestTimerStop

Function TestTimerStop

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

Source from the content-addressed store, hash-verified

90}
91
92func TestTimerStop(t *testing.T) {
93 // Set a small MaxSleepTime for testing
94 setMaxSleepTimeForTest(t, testMaxSleepTime)
95
96 t.Run("stop before trigger", func(t *testing.T) {
97 start := clock.Now()
98 target := start.Add(100 * time.Millisecond)
99
100 timer := NewTimer(clock.Now, target)
101 timer.Stop()
102 time.Sleep(20 * time.Millisecond)
103
104 select {
105 case <-timer.C:
106 t.Error("timer triggered after being stopped")
107 default:
108 }
109 })
110
111 t.Run("stop after trigger", func(t *testing.T) {
112 start := clock.Now()
113 target := start.Add(10 * time.Millisecond)
114
115 timer := NewTimer(clock.Now, target)
116 <-timer.C
117 timer.Stop()
118 })
119}
120
121func TestTimerConcurrentStop(t *testing.T) {
122 // Set a small MaxSleepTime for testing

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