-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock_test.go
More file actions
96 lines (87 loc) · 1.69 KB
/
Copy pathclock_test.go
File metadata and controls
96 lines (87 loc) · 1.69 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package clock
import (
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSysClockNow(t *testing.T) {
ck := New()
now := ck.Now()
require.NotNil(t, now)
assert.True(t, time.Now().After(now))
}
func TestSysClockTicker(t *testing.T) {
ck := New()
d := osDelta()
before := time.Now()
ticker := ck.NewTicker(d)
require.NotNil(t, ticker)
c := ticker.C()
require.NotNil(t, c)
<-c
require.True(t, time.Since(before) >= d)
ticker.Reset(d)
<-c
assert.True(t, time.Since(before) >= 2*d)
ticker.Stop()
}
func TestSysClockTimer(t *testing.T) {
ck := New()
d := osDelta()
before := time.Now()
timer := ck.NewTimer(d)
require.NotNil(t, timer)
c := timer.C()
require.NotNil(t, c)
<-c
require.True(t, time.Since(before) >= d)
timer.Reset(d)
<-c
assert.True(t, time.Since(before) >= 2*d)
timer.Stop()
}
func TestSysClockSleep(t *testing.T) {
ck := New()
before := time.Now()
d := osDelta()
ck.Sleep(d)
assert.True(t, time.Since(before) >= d)
}
func TestSysClockAfter(t *testing.T) {
ck := New()
d := osDelta()
before := time.Now()
c := ck.After(d)
require.NotNil(t, c)
<-c
assert.True(t, time.Since(before) >= d)
}
func TestSysClockAfterFunc(t *testing.T) {
ck := New()
d := osDelta()
before := time.Now()
var wg sync.WaitGroup
wg.Add(1)
f := func() {
wg.Done()
}
timer := ck.AfterFunc(d, f)
require.NotNil(t, timer)
c := timer.C()
require.Nil(t, c)
timer.Reset(d * 2)
wg.Wait()
assert.True(t, time.Since(before) >= d*2)
timer.Stop()
}
func TestSysClockTick(t *testing.T) {
ck := New()
d := osDelta()
before := time.Now()
c := ck.Tick(d)
require.NotNil(t, c)
<-c
assert.True(t, time.Since(before) >= d)
}