MCPcopy Create free account
hub / github.com/desertbit/timer / TestReset

Function TestReset

timer_test.go:174–199  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

172}
173
174func TestReset(t *testing.T) {
175 start := time.Now()
176 timer := NewTimer(time.Second)
177 wasActive := timer.Reset(2 * time.Second)
178 if !wasActive {
179 t.Errorf("reset timer: was active is false")
180 }
181
182 <-timer.C
183
184 if int(time.Since(start).Seconds()) != 2 {
185 t.Errorf("took ~%v seconds, should be ~2 seconds\n", int(time.Since(start).Seconds()))
186 }
187
188 start = time.Now()
189 wasActive = timer.Reset(time.Second)
190 if wasActive {
191 t.Errorf("reset timer: was active is true")
192 }
193
194 <-timer.C
195
196 if int(time.Since(start).Seconds()) != 1 {
197 t.Errorf("took ~%v seconds, should be ~1 seconds\n", int(time.Since(start).Seconds()))
198 }
199}
200
201func TestNegativeReset(t *testing.T) {
202 // Timeout for -1 seconds.

Callers

nothing calls this directly

Calls 2

ResetMethod · 0.95
NewTimerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…