forked from go-co-op/gocron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor_test.go
67 lines (53 loc) · 1.16 KB
/
executor_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
package gocron
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"
)
func Test_ExecutorExecute(t *testing.T) {
e := newExecutor()
wg := &sync.WaitGroup{}
wg.Add(1)
e.start()
e.jobFunctions <- jobFunction{
funcName: "test_fn",
function: func(arg string) {
assert.Equal(t, arg, "test")
wg.Done()
},
parameters: []interface{}{"test"},
isRunning: atomic.NewBool(false),
runStartCount: atomic.NewInt64(0),
runFinishCount: atomic.NewInt64(0),
}
wg.Wait()
e.stop()
}
func Test_ExecutorPanicHandling(t *testing.T) {
panicHandled := make(chan bool, 1)
handler := func(jobName string, recoverData interface{}) {
panicHandled <- true
}
SetPanicHandler(handler)
e := newExecutor()
wg := &sync.WaitGroup{}
wg.Add(1)
e.start()
e.jobFunctions <- jobFunction{
funcName: "test_fn",
function: func() {
defer wg.Done()
a := make([]string, 0)
a[0] = "This will panic"
},
parameters: nil,
isRunning: atomic.NewBool(false),
runStartCount: atomic.NewInt64(0),
runFinishCount: atomic.NewInt64(0),
}
wg.Wait()
e.stop()
state := <-panicHandled
assert.Equal(t, state, true)
}