Use Ticker in Repeat again to avoid drift

This commit is contained in:
Ethan Frey
2017-12-07 11:22:54 +01:00
parent 8797197cdf
commit cc7a87e27c
2 changed files with 17 additions and 23 deletions

View File

@ -39,11 +39,11 @@ func (c *rCounter) Read() {
func TestRepeat(test *testing.T) {
assert := asrt.New(test)
dur := time.Duration(50) * time.Millisecond
dur := time.Duration(100) * time.Millisecond
short := time.Duration(20) * time.Millisecond
// delay waits for cnt durations, an a little extra
delay := func(cnt int) time.Duration {
return time.Duration(cnt)*dur + time.Duration(5)*time.Millisecond
return time.Duration(cnt)*dur + time.Duration(10)*time.Millisecond
}
t := NewRepeatTimer("bar", dur)
@ -70,7 +70,7 @@ func TestRepeat(test *testing.T) {
// after a stop, nothing more is sent
stopped := t.Stop()
assert.True(stopped)
time.Sleep(delay(7))
time.Sleep(delay(2))
assert.Equal(6, c.Count())
// extra calls to stop don't block