forked from YaoApp/gou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule_test.go
92 lines (76 loc) · 2.03 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package gou
import (
"fmt"
"os"
"path"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestLoadSchedule(t *testing.T) {
scheduleLoad(t)
assert.Equal(t, 2, len(Schedules))
assert.NotPanics(t, func() { SelectSchedule("sendmail") })
assert.NotPanics(t, func() { SelectSchedule("mail") })
}
func TestScheduleUseTask(t *testing.T) {
// scheduleLoad(t)
// go SelectTask("mail").Start()
// defer SelectTask("mail").Stop()
// sch := SelectSchedule("sendmail")
// sch.Start()
// fmt.Println("Start", sch.Enabled)
// time.Sleep(80 * time.Second)
// sch.Stop()
// fmt.Println("Stop", sch.Enabled)
// time.Sleep(80 * time.Second)
}
func TestScheduleUseProcess(t *testing.T) {
// scheduleLoad(t)
// sch := SelectSchedule("mail")
// sch.Start()
// fmt.Println("Start", sch.Enabled)
// time.Sleep(80 * time.Second)
// sch.Stop()
// fmt.Println("Stop", sch.Enabled)
// time.Sleep(80 * time.Second)
}
func TestScheduleProcesses(t *testing.T) {
scheduleLoad(t)
res, err := NewProcess("schedules.mail.Start").Exec()
if err != nil {
t.Fatal(err)
}
assert.True(t, res.(map[string]interface{})["enabled"].(bool))
res, err = NewProcess("schedules.mail.Stop").Exec()
if err != nil {
t.Fatal(err)
}
assert.False(t, res.(map[string]interface{})["enabled"].(bool))
}
func scheduleLoad(t *testing.T) {
RegisterProcessHandler("xiang.system.Sleep", func(process *Process) interface{} {
process.ValidateArgNums(1)
ms := process.ArgsInt(0)
time.Sleep(time.Duration(ms) * time.Millisecond)
return nil
})
root := os.Getenv("GOU_TEST_APP_ROOT")
_, err := LoadTask("file://"+path.Join(root, "tasks", "mail.task.json"), "mail")
if err != nil {
t.Fatal(err)
}
err = Yao.Load(path.Join(root, "scripts", "mail.js"), "mail")
if err != nil {
fmt.Println(err)
t.Fatal(err)
}
_, err = LoadSchedule("file://"+path.Join(root, "schedules", "sendmail.sch.json"), "sendmail")
if err != nil {
t.Fatal(err)
}
_, err = LoadSchedule("file://"+path.Join(root, "schedules", "mail.sch.json"), "mail")
if err != nil {
t.Fatal(err)
}
}