forked from AfterShip/email-verifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule_test.go
57 lines (45 loc) · 1.12 KB
/
schedule_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 emailverifier
import (
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestStartScheduleOK(t *testing.T) {
var ops uint32
f := func() {
atomic.AddUint32(&ops, 1)
}
s := newSchedule(time.Second, f)
s.start()
time.Sleep(time.Second * 3)
s.stop()
actual := atomic.LoadUint32(&ops)
assert.Equal(t, uint32(3), actual)
// assert.True(t, uint32(2) <= actual && actual <= uint32(3))
}
func TestNewScheduleOK(t *testing.T) {
f := func() {}
actual := newSchedule(time.Minute, f)
assert.NotNil(t, actual)
}
func TestNewScheduleOK_FuncWithParams(t *testing.T) {
f := func(a, b int) bool {
return a > b
}
actual := newSchedule(time.Minute, f, 3, 4)
assert.NotNil(t, actual)
assert.Equal(t, actual.jobParams, []interface{}{3, 4})
}
func TestNewScheduleWithWrongFunc(t *testing.T) {
f := "test"
actual := newSchedule(time.Minute, f)
assert.Nil(t, actual.jobParams)
assert.Equal(t, actual.jobFunc, f)
}
func TestRunScheduleFailedWithWrongFunc(t *testing.T) {
f := "test"
actual := newSchedule(time.Minute, f)
assert.Equal(t, actual.jobFunc, f)
assert.NotPanics(t, actual.start)
}