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

Function TestResetBehavior

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

Source from the content-addressed store, hash-verified

296}
297
298func TestResetBehavior(t *testing.T) {
299 start := time.Now()
300
301 // Start a new timer with a timeout of 1 second.
302 timer := NewTimer(1 * time.Second)
303
304 // Wait for 2 seconds.
305 // Meanwhile the timer fired filled the channel.
306 time.Sleep(2 * time.Second)
307
308 // Reset the timer. This should act exactly as creating a new timer.
309 timer.Reset(1 * time.Second)
310
311 // However this will fire immediately, because the channel was not drained.
312 // See issue: https://github.com/golang/go/issues/11513
313 <-timer.C
314
315 if int(time.Since(start).Seconds()) != 3 {
316 t.Errorf("took ~%v seconds, should be ~3 seconds\n", int(time.Since(start).Seconds()))
317 }
318}
319
320func TestMultipleTimersForValidTimeouts(t *testing.T) {
321 var wg sync.WaitGroup

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…