-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_test.go
executable file
·51 lines (43 loc) · 1 KB
/
global_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
// Copyright (c) 2018,TianJin Tomatox Technology Ltd. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package scheduler
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAfterFunc(t *testing.T) {
assert.NotPanics(t, func() {
out := make(chan bool, 1)
mj, _ := AfterFunc(time.Millisecond*10, func() {
out <- true
}, nil)
v := <-out
assert.True(t, v)
mj.Cancel()
})
}
func TestPeriodFunc(t *testing.T) {
assert.NotPanics(t, func() {
out := make(chan bool, 1)
mjob, _ := PeriodFunc(0, time.Millisecond, func() {
out <- true
}, nil)
<-out
v := <-out
assert.True(t, v)
mjob.Cancel()
})
}
func TestCronFunc(t *testing.T) {
assert.NotPanics(t, func() {
var calls = 0
mjob, _ := CronFunc("* * * * * *", func() { calls++ }, nil)
defer mjob.Cancel()
<-time.After(time.Second + 100*time.Nanosecond)
if calls != 1 {
t.Errorf("called %d times, expected 1\n", calls)
}
})
}