-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtask_test.go
103 lines (83 loc) · 1.93 KB
/
task_test.go
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
97
98
99
100
101
102
103
package timing
import (
"time"
"fmt"
"testing"
)
//test add Func
func Test_AddFunc(t *testing.T) {
cron := NewCron()
go cron.Start()
cron.AddFunc(time.Now().UnixNano()+int64(time.Second*1), func() {
fmt.Println("one second after")
})
cron.AddFunc(time.Now().UnixNano()+int64(time.Second*1), func() {
fmt.Println("one second after, task second")
})
cron.AddFunc(time.Now().UnixNano()+int64(time.Second*10), func() {
fmt.Println("ten second after")
})
timer := time.NewTimer(11 * time.Second)
for {
select {
case <-timer.C:
fmt.Println("over")
}
break
}
}
//test add space task func
func Test_AddFuncSpace(t *testing.T) {
cron := NewScheduler()
go cron.Start()
cron.AddFuncSpace(1, time.Now().UnixNano()+int64(time.Second*1), func() {
fmt.Println("one second after")
})
cron.AddFuncSpace(1, time.Now().UnixNano()+int64(time.Second*20),func() {
fmt.Println("one second after, task second")
})
cron.AddFunc(time.Now().UnixNano()+int64(time.Second*10), func() {
fmt.Println("ten second after")
})
timer := time.NewTimer(11 * time.Second)
for {
select {
case <-timer.C:
fmt.Println("over")
}
break
}
}
//test add Task and timing add Task
func Test_AddTask(t *testing.T) {
cron := NewCron()
go cron.Start()
cron.AddTask(&Task{
Job:FuncJob(func() {
fmt.Println("hello cron")
}),
RunTime:time.Now().UnixNano()+int64(time.Second*2),
})
cron.AddTask(&Task{
Job:FuncJob(func() {
fmt.Println("hello cron1")
}),
RunTime:time.Now().UnixNano()+int64(time.Second*3),
})
cron.AddTask(&Task{
Job: FuncJob(func() {
fmt.Println("hello cron2 loop")
}),
RunTime: time.Now().UnixNano() + int64(time.Second*4),
Spacing: 1,
EndTime: time.Now().UnixNano() + 9*(int64(time.Second)),
})
timer := time.NewTimer(10 * time.Second)
for {
select {
case <-timer.C:
fmt.Println("over")
}
break
}
}