-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler_test.go
57 lines (45 loc) · 1.01 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
package quartz
import (
"context"
"fmt"
"testing"
"time"
)
func TestScheduler(t *testing.T) {
scheduler := NewTimingWheel(time.Millisecond*10, 20)
scheduler.Run()
for i := 1; i < 5000000; i++ {
scheduler.ScheduleFunc(time.Millisecond*10*time.Duration(i), func(ctx context.Context) {
})
}
st := time.Now()
_ = scheduler.ScheduleFunc(time.Millisecond*200, func(ctx context.Context) {
ed := time.Now()
fmt.Println(ed.UnixMilli() - st.UnixMilli() - 200)
st = ed
})
time.Sleep(time.Second * 2)
//scheduler.Stop()
for {
}
}
func TestScheduler2(t *testing.T) {
scheduler := NewTimingWheel(time.Millisecond*10, 60)
scheduler.Run()
var k int64 = 1
for i := 1; i < 10000000; i++ {
if i%1000 == 0 {
k++
}
scheduler.ScheduleFunc(time.Millisecond*10*time.Duration(k), func(ctx context.Context) {
})
}
st := time.Now()
scheduler.ScheduleFunc(time.Millisecond*200, func(ctx context.Context) {
ed := time.Now()
fmt.Println(ed.UnixMilli() - st.UnixMilli() - 200)
st = ed
})
for {
}
}