-
Notifications
You must be signed in to change notification settings - Fork 75
/
dcron_locally_test.go
51 lines (45 loc) · 1017 Bytes
/
dcron_locally_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
package dcron_test
import (
"testing"
"time"
"github.com/libi/dcron"
"github.com/libi/dcron/cron"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type DcronLocallyTestSuite struct {
suite.Suite
}
func (s *DcronLocallyTestSuite) TestNormal() {
dcr := dcron.NewDcronWithOption(
"not a necessary servername",
nil,
dcron.RunningLocally(),
dcron.CronOptionSeconds(),
dcron.CronOptionChain(
cron.Recover(
cron.DefaultLogger,
)))
s.Assert().NotNil(dcr)
runningTime := 60 * time.Second
t := s.T()
var err error
err = dcr.AddFunc("job1", "*/5 * * * * *", func() {
t.Log(time.Now())
})
require.Nil(t, err)
err = dcr.AddFunc("job2", "*/8 * * * * *", func() {
panic("test panic")
})
require.Nil(t, err)
err = dcr.AddFunc("job3", "*/2 * * * * *", func() {
t.Log("job3:", time.Now())
})
require.Nil(t, err)
dcr.Start()
<-time.After(runningTime)
dcr.Stop()
}
func TestDcronLocallyTestSuite(t *testing.T) {
suite.Run(t, &DcronLocallyTestSuite{})
}