l_notify/notify_test.go

45 lines
886 B
Go

package l_notify
import (
"fmt"
"gitea.cdlsxd.cn/self-tools/l_request"
cron2 "github.com/robfig/cron/v3"
"testing"
"time"
)
func TestNotify(t *testing.T) {
var a int32
c := &Notify{
DoFuc: func() (l_request.Response, error) {
a++
return l_request.Response{StatusCode: int(a)}, nil
},
DelayList: []int32{3},
ResultHandle: func(r l_request.Response, e error) (stop bool) {
fmt.Printf("%d-----%s\n", r.StatusCode, time.Now().Format(time.TimeOnly))
if r.StatusCode == 5 {
a = 0
return true
}
return false
},
}
err := c.Notify()
if err != nil {
fmt.Print(a)
}
}
func TestNotify2(t *testing.T) {
cron := cron2.New()
id, _ := cron.AddFunc("@every 1s", func() { fmt.Println("Every 1") })
cron.Start()
time.Sleep(3 * time.Second)
cron.Remove(id)
cron.AddFunc("@every 1s", func() { fmt.Println("Every 2") })
//cron.Start()
select {}
}