github.com/ngicks/gokugen@v0.0.5/common/timer_test.go (about) 1 package common_test 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/ngicks/gokugen/common" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestTimer(t *testing.T) { 12 timer := common.NewTimerImpl() 13 14 now := time.Now() 15 timer.Reset(now, now) 16 17 require.InDelta(t, now.UnixNano(), (<-timer.GetChan()).UnixNano(), float64(time.Millisecond)) 18 19 timer.Reset(now.Add(-time.Second), now) 20 // emit fast. 21 require.InDelta(t, now.UnixNano(), (<-timer.GetChan()).UnixNano(), float64(time.Millisecond)) 22 }