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}
0 commit comments