-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner_test.go
49 lines (43 loc) · 1.65 KB
/
scanner_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
package gta
import (
"testing"
"github.com/panjf2000/ants/v2"
"github.com/smartystreets/goconvey/convey"
)
func Test_taskScannerImp_claimInitializedTask(t *testing.T) {
convey.Convey("Test_taskScannerImp_claimInitializedTask", t, func() {
convey.Convey("ctx cancelled", func() {
tc, _ := newOptions(testDB("Test_taskScannerImp_claimInitializedTask"), "tasks")
tr := &taskRegisterImp{}
tdal := &taskDALImp{options: tc}
tscn := &taskScannerImp{options: tc, register: tr, dal: tdal}
_ = tr.Register("t1", TaskDefinition{Handler: testWrappedHandler()})
_ = tdal.Create(tc.getDB(), &Task{TaskKey: "t1", TaskStatus: TaskStatusInitialized})
tc.cancel()
task, err := tscn.claimInitializedTask()
convey.So(err, convey.ShouldBeNil)
convey.So(task, convey.ShouldBeNil)
})
convey.Convey("error", func() {
tc, _ := newOptions(testDB("Test_taskScannerImp_claimInitializedTask"), "not exist")
tr := &taskRegisterImp{}
tdal := &taskDALImp{options: tc}
tscn := &taskScannerImp{options: tc, register: tr, dal: tdal}
_, err := tscn.claimInitializedTask()
convey.So(err, convey.ShouldNotBeNil)
})
})
}
func Test_taskScannerImp_scanAndSchedule(t *testing.T) {
convey.Convey("Test_taskScannerImp_scanAndSchedule", t, func() {
convey.Convey("error", func() {
tc, _ := newOptions(testDB("Test_taskScannerImp_scanAndSchedule"), "not exist")
tr := &taskRegisterImp{}
tdal := &taskDALImp{options: tc}
pool, _ := ants.NewPool(1)
tsch := &taskSchedulerImp{pool: pool}
tscn := &taskScannerImp{options: tc, register: tr, dal: tdal, scheduler: tsch}
convey.So(func() { tscn.scanAndSchedule() }, convey.ShouldNotPanic)
})
})
}