Skip to content

Commit 8c8bf64

Browse files
authored
去除依赖 (#21)
1 parent f3de2a2 commit 8c8bf64

File tree

5 files changed

+102
-62
lines changed

5 files changed

+102
-62
lines changed

go.mod

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,4 @@ module github.com/antlabs/timer
22

33
go 1.19
44

5-
require (
6-
github.com/antlabs/stl v0.0.1
7-
github.com/stretchr/testify v1.6.1
8-
gopkg.in/go-playground/assert.v1 v1.2.1
9-
)
10-
11-
require (
12-
github.com/davecgh/go-spew v1.1.0 // indirect
13-
github.com/pmezard/go-difflib v1.0.0 // indirect
14-
gopkg.in/yaml.v3 v3.0.0 // indirect
15-
)
5+
require github.com/antlabs/stl v0.0.2

go.sum

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
1-
github.com/antlabs/stl v0.0.1 h1:TRD3csCrjREeLhLoQ/supaoCvFhNLBTNIwuRGrDIs6Q=
2-
github.com/antlabs/stl v0.0.1/go.mod h1:wvVwP1loadLG3cRjxUxK8RL4Co5xujGaZlhbztmUEqQ=
3-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8-
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
9-
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
10-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
11-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12-
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
13-
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
14-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
15-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
16-
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
17-
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1+
github.com/antlabs/stl v0.0.2 h1:sna1AXR5yIkNE9lWhCcKbheFJSVfCa3vugnGyakI79s=
2+
github.com/antlabs/stl v0.0.2/go.mod h1:kKrO4xrn9cfS1mJVo+/BqePZjAYMXqD0amGF2Ouq7ac=

min_heap_test.go

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"sync/atomic"
55
"testing"
66
"time"
7-
8-
"github.com/stretchr/testify/assert"
97
)
108

119
// 测试AfterFunc有没有运行以及时间间隔可对
@@ -31,10 +29,14 @@ func Test_MinHeap_AfterFunc_Run(t *testing.T) {
3129
close(tc)
3230
for tv := range tc {
3331
if tv < time.Millisecond || tv > 2*time.Millisecond {
34-
assert.Fail(t, "tc < time.Millisecond tc > 2*time.Millisecond")
32+
t.Errorf("tc < time.Millisecond tc > 2*time.Millisecond")
33+
3534
}
3635
}
37-
assert.Equal(t, atomic.LoadInt32(&count), int32(2))
36+
if atomic.LoadInt32(&count) != 2 {
37+
t.Errorf("count != 2")
38+
}
39+
3840
})
3941

4042
t.Run("10ms", func(t *testing.T) {
@@ -63,7 +65,10 @@ func Test_MinHeap_AfterFunc_Run(t *testing.T) {
6365
}
6466
// cnt++
6567
}
66-
assert.Equal(t, atomic.LoadInt32(&count), int32(2))
68+
if atomic.LoadInt32(&count) != 2 {
69+
t.Errorf("count != 2")
70+
}
71+
6772
})
6873

6974
t.Run("90ms", func(t *testing.T) {
@@ -74,7 +79,10 @@ func Test_MinHeap_AfterFunc_Run(t *testing.T) {
7479
tm.AfterFunc(time.Millisecond*90, func() { atomic.AddInt32(&count, 2) })
7580

7681
time.Sleep(time.Millisecond * 180)
77-
assert.Equal(t, atomic.LoadInt32(&count), int32(3))
82+
if atomic.LoadInt32(&count) != 3 {
83+
t.Errorf("count != 3")
84+
}
85+
7886
})
7987
}
8088

@@ -99,7 +107,10 @@ func Test_MinHeap_ScheduleFunc_Run(t *testing.T) {
99107
}()
100108

101109
time.Sleep(time.Millisecond * 5)
102-
assert.Equal(t, atomic.LoadInt32(&count), int32(2))
110+
if atomic.LoadInt32(&count) != 2 {
111+
t.Errorf("count != 2")
112+
}
113+
103114
})
104115

105116
t.Run("10ms", func(t *testing.T) {
@@ -133,7 +144,11 @@ func Test_MinHeap_ScheduleFunc_Run(t *testing.T) {
133144
}
134145
cnt++
135146
}
136-
assert.Equal(t, atomic.LoadInt32(&count), int32(2))
147+
148+
if atomic.LoadInt32(&count) != 2 {
149+
t.Errorf("count != 2")
150+
}
151+
137152
})
138153

139154
t.Run("30ms", func(t *testing.T) {
@@ -154,7 +169,10 @@ func Test_MinHeap_ScheduleFunc_Run(t *testing.T) {
154169
}()
155170

156171
time.Sleep(time.Millisecond * 70)
157-
assert.Equal(t, atomic.LoadInt32(&count), int32(2))
172+
if atomic.LoadInt32(&count) != 2 {
173+
t.Errorf("count != 2")
174+
}
175+
158176
})
159177
}
160178

@@ -170,7 +188,9 @@ func Test_Run_Stop(t *testing.T) {
170188
tm.Stop()
171189
}()
172190
tm.Run()
173-
assert.Equal(t, atomic.LoadUint32(&count), uint32(2))
191+
if atomic.LoadUint32(&count) != 2 {
192+
t.Errorf("count != 2")
193+
}
174194
})
175195
}
176196

@@ -219,8 +239,14 @@ func Test_CustomFunc(t *testing.T) {
219239
}
220240
cnt++
221241
}
222-
assert.Equal(t, atomic.LoadUint32(&count), uint32(2))
223-
assert.Equal(t, mh.runCount, uint32(1))
242+
if atomic.LoadUint32(&count) != 2 {
243+
t.Errorf("count != 2")
244+
}
245+
246+
if mh.runCount != uint32(1) {
247+
t.Errorf("mh.runCount != 1")
248+
}
249+
224250
})
225251
}
226252

@@ -242,6 +268,9 @@ func Test_RunCount(t *testing.T) {
242268

243269
time.Sleep(time.Millisecond * 15)
244270
tm.Stop()
245-
assert.Equal(t, count, uint32(max))
271+
if count != uint32(max) {
272+
t.Errorf("count != %d", max)
273+
}
274+
246275
})
247276
}

time_wheel_test.go

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,43 @@ import (
66
"sync/atomic"
77
"testing"
88
"time"
9-
10-
"github.com/stretchr/testify/assert"
119
)
1210

1311
func Test_maxVal(t *testing.T) {
14-
assert.Equal(t, maxVal(), uint64(math.MaxUint32))
12+
13+
if maxVal() != uint64(math.MaxUint32) {
14+
t.Error("maxVal() != uint64(math.MaxUint32)")
15+
}
1516
}
1617

1718
func Test_LevelMax(t *testing.T) {
18-
assert.Equal(t, levelMax(1), uint64(1<<(nearShift+levelShift)))
19-
assert.Equal(t, levelMax(2), uint64(1<<(nearShift+2*levelShift)))
20-
assert.Equal(t, levelMax(3), uint64(1<<(nearShift+3*levelShift)))
21-
assert.Equal(t, levelMax(4), uint64(1<<(nearShift+4*levelShift)))
19+
if levelMax(1) != uint64(1<<(nearShift+levelShift)) {
20+
t.Error("levelMax(1) != uint64(1<<(nearShift+levelShift))")
21+
}
22+
23+
if levelMax(2) != uint64(1<<(nearShift+2*levelShift)) {
24+
t.Error("levelMax(2) != uint64(1<<(nearShift+2*levelShift))")
25+
}
26+
27+
if levelMax(3) != uint64(1<<(nearShift+3*levelShift)) {
28+
t.Error("levelMax(3) != uint64(1<<(nearShift+3*levelShift))")
29+
}
30+
31+
if levelMax(4) != uint64(1<<(nearShift+4*levelShift)) {
32+
t.Error("levelMax(4) != uint64(1<<(nearShift+4*levelShift))")
33+
}
34+
2235
}
2336

2437
func Test_GenVersion(t *testing.T) {
25-
assert.Equal(t, genVersionHeight(1, 0xf), uint64(0x0001000f00000000))
26-
assert.Equal(t, genVersionHeight(1, 64), uint64(0x0001004000000000))
38+
if genVersionHeight(1, 0xf) != uint64(0x0001000f00000000) {
39+
t.Error("genVersionHeight(1, 0xf) != uint64(0x0001000f00000000)")
40+
}
41+
42+
if genVersionHeight(1, 64) != uint64(0x0001004000000000) {
43+
t.Error("genVersionHeight(2, 0xf) != uint64(0x0001004000000000)")
44+
}
45+
2746
}
2847

2948
// 测试1小时
@@ -49,7 +68,11 @@ func Test_hour(t *testing.T) {
4968
case <-done:
5069
case <-time.After(time.Second / 100):
5170
}
52-
assert.True(t, *testHour)
71+
72+
if *testHour == false {
73+
t.Error("testHour == false")
74+
}
75+
5376
}
5477

5578
// 测试周期性定时器, 5s
@@ -84,8 +107,9 @@ func Test_ScheduleFunc_5s(t *testing.T) {
84107
case <-time.After(time.Second / 100):
85108
}
86109

87-
assert.Equal(t, total, first5)
88-
110+
if total != first5 {
111+
t.Errorf("total:%d != first5:%d\n", total, first5)
112+
}
89113
}
90114

91115
// 测试周期性定时器, 1hour
@@ -119,7 +143,9 @@ func Test_ScheduleFunc_hour(t *testing.T) {
119143
case <-time.After(time.Second / 100):
120144
}
121145

122-
assert.Equal(t, total, first5)
146+
if total != first5 {
147+
t.Errorf("total:%d != first5:%d\n", total, first5)
148+
}
123149

124150
}
125151

@@ -154,6 +180,7 @@ func Test_ScheduleFunc_day(t *testing.T) {
154180
case <-time.After(time.Second / 100):
155181
}
156182

157-
assert.Equal(t, total, first5)
158-
183+
if total != first5 {
184+
t.Errorf("total:%d != first5:%d\n", total, first5)
185+
}
159186
}

timer_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"sync/atomic"
66
"testing"
77
"time"
8-
9-
"gopkg.in/go-playground/assert.v1"
108
)
119

1210
func Test_ScheduleFunc(t *testing.T) {
@@ -28,7 +26,10 @@ func Test_ScheduleFunc(t *testing.T) {
2826
}()
2927

3028
tm.Run()
31-
assert.Equal(t, atomic.LoadUint32(&count), uint32(5))
29+
if count != 5 {
30+
t.Errorf("count:%d != 5\n", count)
31+
}
32+
3233
}
3334

3435
func Test_AfterFunc(t *testing.T) {
@@ -64,7 +65,10 @@ func Test_AfterFunc(t *testing.T) {
6465
tm.Stop()
6566
}()
6667
tm.Run()
67-
assert.Equal(t, atomic.LoadUint32(&count), uint32(2))
68+
if count != 2 {
69+
t.Errorf("count:%d != 2\n", count)
70+
}
71+
6872
}
6973

7074
func Test_Node_Stop_1(t *testing.T) {
@@ -80,7 +84,9 @@ func Test_Node_Stop_1(t *testing.T) {
8084
}()
8185

8286
tm.Run()
83-
assert.NotEqual(t, count, 1)
87+
if count != 1 {
88+
t.Errorf("count:%d == 1\n", count)
89+
}
8490
}
8591

8692
func Test_Node_Stop(t *testing.T) {
@@ -96,5 +102,8 @@ func Test_Node_Stop(t *testing.T) {
96102
}()
97103
tm.Run()
98104

99-
assert.NotEqual(t, count, 1)
105+
if count == 1 {
106+
t.Errorf("count:%d == 1\n", count)
107+
}
108+
100109
}

0 commit comments

Comments
 (0)