-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_test.go
More file actions
43 lines (35 loc) · 728 Bytes
/
timer_test.go
File metadata and controls
43 lines (35 loc) · 728 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
40
41
42
43
package timer
import (
"testing"
"time"
)
func Test_NewTimingWheel(t *testing.T) {
timing := NewTimingWheel(
NewSimpleScheduler(NewSimpleDispatcher()),
64,
time.Second,
1, 2, 4, 8)
begin := time.Now().Unix()
t0 := timing.After(10*time.Second, func() {
t.Error("no cancel")
})
timing.Add(NewTimerTable(func() {
timing.Cancel(t0)
}, 8))
timing.After(28*time.Second, func() {
if v := time.Now().Unix() - begin; 28 != v {
t.Error("After Real: ", v)
}
timing.Stop()
})
interval := time.Now().Unix()
timing.Interval(2*time.Second, func() {
now := time.Now().Unix()
if v := now - interval; 2 != v {
t.Error("Interval Real: ", v)
}
interval = now
})
timing.Start()
timing.Wait()
}