-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmultitick_test.go
More file actions
39 lines (35 loc) · 860 Bytes
/
multitick_test.go
File metadata and controls
39 lines (35 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package multitick
// Copyright (c) 2013 VividCortex, Inc. All rights reserved.
// Please see the LICENSE file for applicable license terms.
import (
"testing"
"time"
)
func TestTicker(t *testing.T) {
tick := NewTicker(time.Second, time.Millisecond*250)
c := tick.Subscribe()
chans := make([]<-chan time.Time, 0)
i := 0
for now := range c {
chans = append(chans, tick.Subscribe())
if i > 5 {
tick.Stop()
break
}
i++
t.Log(now, now.Nanosecond())
if now.Nanosecond() < 247000000 || now.Nanosecond() > 253000000 {
t.Errorf("%v isn't within 3ms of 250ms offset", now)
}
}
}
func TestDropped(t *testing.T) {
tick := NewTicker(time.Millisecond, 0)
tick.Subscribe()
time.Sleep(time.Second)
tick.Stop()
t.Log(tick.Dropped())
if tick.Dropped() < 800 {
t.Errorf("got %v dropped ticks, wanted at least 800", tick.Dropped())
}
}