2018-12-02 19:18:42 +00:00
|
|
|
package curl2info
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-12-03 12:01:19 +00:00
|
|
|
"runtime"
|
2018-12-02 19:18:42 +00:00
|
|
|
"testing"
|
2018-12-03 11:22:43 +00:00
|
|
|
"time"
|
2018-12-02 19:18:42 +00:00
|
|
|
)
|
|
|
|
|
2018-12-03 11:22:43 +00:00
|
|
|
// type LRValue struct {
|
|
|
|
// left, right int
|
|
|
|
// }
|
|
|
|
|
2018-12-04 12:00:30 +00:00
|
|
|
func TestParseCrontab(t *testing.T) {
|
|
|
|
// crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围
|
2018-12-05 03:57:16 +00:00
|
|
|
crontab := "* * * * *"
|
2018-12-03 11:22:43 +00:00
|
|
|
|
2018-12-04 12:00:30 +00:00
|
|
|
PrintMemUsage()
|
2018-12-03 11:22:43 +00:00
|
|
|
|
2018-12-05 06:51:36 +00:00
|
|
|
ty := newTrieYear()
|
2018-12-04 20:25:40 +00:00
|
|
|
cron := NewCrontab(crontab)
|
|
|
|
ty.FromCrontab(cron)
|
2018-12-05 03:57:16 +00:00
|
|
|
|
2018-12-05 06:51:36 +00:00
|
|
|
if len(ty.GetPlanTime(cron, time.Now(), 10)) != 10 {
|
|
|
|
t.Error("GetPlanTime error len != 10")
|
|
|
|
}
|
2018-12-05 03:57:16 +00:00
|
|
|
|
|
|
|
cron.CreateYearPlan()
|
2018-12-05 06:51:36 +00:00
|
|
|
if !cron.TimeUp(time.Now()) {
|
|
|
|
t.Error("timeup error")
|
2018-12-05 03:57:16 +00:00
|
|
|
}
|
2018-12-03 11:22:43 +00:00
|
|
|
|
2018-12-03 12:01:19 +00:00
|
|
|
PrintMemUsage()
|
|
|
|
|
2018-12-04 12:00:30 +00:00
|
|
|
}
|
2018-12-03 18:55:34 +00:00
|
|
|
|
2018-12-04 12:00:30 +00:00
|
|
|
func TestCrontabPlus(t *testing.T) {
|
|
|
|
// crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围
|
|
|
|
// crondata := NewCrontab("*22 * * * *")
|
2018-12-03 12:01:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrintMemUsage() {
|
|
|
|
var m runtime.MemStats
|
|
|
|
runtime.ReadMemStats(&m)
|
|
|
|
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
|
|
|
|
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
|
|
|
|
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
|
|
|
|
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
|
|
|
|
fmt.Printf("\tNumGC = %v\n", m.NumGC)
|
|
|
|
}
|
|
|
|
|
|
|
|
func bToMb(b uint64) uint64 {
|
|
|
|
return b / 1024 / 1024
|
2018-12-02 19:18:42 +00:00
|
|
|
}
|