mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve unit testing case for package gtimer
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
package gtimer
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/container/garray"
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
"github.com/gogf/gf/test/gtest"
|
||||
"testing"
|
||||
@ -16,34 +17,34 @@ import (
|
||||
func TestTimer_Proceed(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
index := gtype.NewInt()
|
||||
slice := make([]int, 0)
|
||||
array := garray.New(true)
|
||||
timer := doNewWithoutAutoStart(10, 60*time.Millisecond, 6)
|
||||
timer.nowFunc = func() time.Time {
|
||||
return time.Now().Add(time.Duration(index.Add(1)) * time.Millisecond * 60)
|
||||
}
|
||||
timer.AddOnce(2*time.Second, func() {
|
||||
slice = append(slice, 1)
|
||||
array.Append(1)
|
||||
})
|
||||
timer.AddOnce(1*time.Minute, func() {
|
||||
slice = append(slice, 2)
|
||||
array.Append(2)
|
||||
})
|
||||
timer.AddOnce(5*time.Minute, func() {
|
||||
slice = append(slice, 3)
|
||||
array.Append(3)
|
||||
})
|
||||
timer.AddOnce(1*time.Hour, func() {
|
||||
slice = append(slice, 4)
|
||||
array.Append(4)
|
||||
})
|
||||
timer.AddOnce(100*time.Minute, func() {
|
||||
slice = append(slice, 5)
|
||||
array.Append(5)
|
||||
})
|
||||
timer.AddOnce(2*time.Hour, func() {
|
||||
slice = append(slice, 6)
|
||||
array.Append(6)
|
||||
})
|
||||
for i := 0; i < 500000; i++ {
|
||||
timer.wheels[0].proceed()
|
||||
time.Sleep(10 * time.Microsecond)
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
t.Assert(slice, []int{1, 2, 3, 4, 5, 6})
|
||||
t.Assert(array.Slice(), []int{1, 2, 3, 4, 5, 6})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user