-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer_test.go
60 lines (37 loc) · 890 Bytes
/
timer_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"testing"
"time"
)
func TestNewRestableTimer(t *testing.T) {
r := NewResetableTimer(1 * time.Second)
if r == nil {
t.Error("NewResetableTimer must return a pointer to ResetableTimer")
}
}
func TestResetableTimerOperations(t *testing.T) {
r := NewResetableTimer(100 * time.Millisecond)
if r.cancelCount != 0 {
t.Error("Cancel count of ResetableTimer must be set to zero")
}
r.Cancel()
st := <-r.Status
if st != RTCancel {
t.Error("Invalid status for cancel operation")
}
go r.Start()
time.Sleep(120 * time.Millisecond)
st = <-r.Status
if st != RTTimeout {
t.Error("ResetableTimer must time out after duration")
}
go r.Start()
time.Sleep(90 * time.Millisecond)
r.Reset()
time.Sleep(90 * time.Millisecond)
r.Cancel()
st = <-r.Status
if st != RTCancel {
t.Error("ResetableTimer reset the timer calling Reset")
}
}