forked from koangel/grapeTimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_test.go
More file actions
82 lines (64 loc) · 1.51 KB
/
Copy pathtimer_test.go
File metadata and controls
82 lines (64 loc) · 1.51 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
package grapeTimer
import (
"fmt"
"testing"
"time"
)
func CallBackOnce(arg1 string, arg2 int, arg3 float32) {
fmt.Println(arg1, arg2, arg3)
}
func CallBackResult(arg1 string, arg2 int, arg3 float32, resultcall func(val float32)) {
fmt.Println(arg1, arg2, arg3)
resultcall(arg3) // 调用CALLBACK去返回数值
}
func Test_CallResult(t *testing.T) {
cb, err := reflectFunc(CallBackResult, "this arg1", 2000, float32(300.5), func(v float32) {
fmt.Println("i'm call back:", v)
})
if err != nil {
t.Error(err)
return
}
callFunc(cb)
}
func Test_CallReflect(t *testing.T) {
cb, err := reflectFunc(CallBackOnce, "this arg1", 2000, float32(300.5))
if err != nil {
t.Error(err)
return
}
callFunc(cb)
}
func Test_JsonSave(t *testing.T) {
InitGrapeScheduler(2*time.Second, false)
Id := NewTickerOnce(1000, CallBackOnce, "this arg1", 2000, float32(300.5))
Json := ToJson(Id)
if len(Json) == 0 {
t.Error("save error")
return
}
fmt.Print(Json)
Id = NewFromJson(Json, CallBackOnce, "this arg1", 2000, float32(300.5))
}
func Test_JsonSaveAll(t *testing.T) {
InitGrapeScheduler(2*time.Second, false)
NewTickerOnce(1000, CallBackOnce, "this arg1", 2000, float32(300.5))
Json := SaveAll()
if len(Json) == 0 {
t.Error("save error")
return
}
fmt.Print(Json)
}
func Benchmark_Parallel(b *testing.B) {
cb, err := reflectFunc(CallBackOnce, "this arg1", 2000, float32(300.5))
if err != nil {
b.Error(err)
return
}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
callFunc(cb)
}
})
}