-
Notifications
You must be signed in to change notification settings - Fork 1
/
scheduler_test.go
114 lines (88 loc) · 2.57 KB
/
scheduler_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
104
105
106
107
108
109
110
111
112
113
114
package goscheduler
import (
"fmt"
"testing"
"time"
)
func TestRepeatEvery(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long running test.")
}
s := new(Scheduler)
s.Init(1)
start := time.Now()
s.RepeatEvery( time.Millisecond * 80,
func() bool {
time.Sleep(time.Millisecond * 20)
fmt.Printf("smoke at: %s\n", time.Since(start))
return true
})
time.Sleep(time.Second * 1)
s.Close()
}
func TestRepeatEvery2ConcurrentJobs(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long running test.")
}
s := new(Scheduler)
s.Init(2)
start := time.Now()
s.RepeatEvery( time.Millisecond * 30,
func() bool {
time.Sleep(time.Millisecond * 20)
fmt.Printf("action1 at: %s\n", time.Since(start))
return true
})
s.RepeatEvery( time.Millisecond * 80,
func() bool {
time.Sleep(time.Millisecond * 20)
fmt.Printf("action2 at: %s\n", time.Since(start))
return true
})
time.Sleep(time.Second * 1)
s.Close()
}
func TestRepeatEvery2JobsWithConcurrency1(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long running test.")
}
s := new(Scheduler)
s.Init(1)
start := time.Now()
s.RepeatEvery( time.Millisecond * 100,
func() bool {
time.Sleep(time.Millisecond * 100)
fmt.Printf("action 100 at: %s\n", time.Since(start))
return true
})
s.RepeatEvery( time.Millisecond * 10,
func() bool {
time.Sleep(time.Millisecond * 10)
fmt.Printf("action 10 at: %s\n", time.Since(start))
return true
})
time.Sleep(time.Second * 1)
s.Close()
}
func TestRepeatForCount(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long running test.")
}
s := new(Scheduler)
s.Init(1)
start := time.Now()
count := 0
s.RepeatForCount( 2,
time.Millisecond * 10,
func() bool {
count++
time.Sleep(time.Millisecond * 50)
fmt.Printf("action at: %s\n", time.Since(start))
return true
})
time.Sleep(time.Millisecond * 500)
s.Close()
if count != 2 {
t.Fatal("Failed to execute required number of times")
}
}