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

Function TestResetChannelClear

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

Source from the content-addressed store, hash-verified

259}
260
261func TestResetChannelClear(t *testing.T) {
262 timer := NewTimer(0)
263 time.Sleep(time.Second)
264
265 if len(timer.C) != 1 {
266 t.Errorf("reset timer: channel should be filled")
267 }
268
269 wasActive := timer.Reset(2 * time.Second)
270 if wasActive {
271 t.Errorf("reset timer: was active is true")
272 }
273
274 if len(timer.C) != 0 {
275 t.Errorf("reset timer: channel should be empty")
276 }
277
278 start := time.Now()
279 <-timer.C
280
281 if int(time.Since(start).Seconds()) != 2 {
282 t.Errorf("took ~%v seconds, should be ~2 seconds\n", int(time.Since(start).Seconds()))
283 }
284}
285
286func TestResetPanic(t *testing.T) {
287 defer func() {

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…