github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/idles/run_test.go (about) 1 // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package idles_test 4 5 import ( 6 "github.com/TeaOSLab/EdgeNode/internal/utils/idles" 7 "github.com/TeaOSLab/EdgeNode/internal/utils/testutils" 8 _ "github.com/iwind/TeaGo/bootstrap" 9 "github.com/iwind/TeaGo/types" 10 timeutil "github.com/iwind/TeaGo/utils/time" 11 "testing" 12 "time" 13 ) 14 15 func TestCheckHourlyLoad(t *testing.T) { 16 for i := 0; i < 10; i++ { 17 idles.CheckHourlyLoad(5) 18 idles.CheckHourlyLoad(1) 19 idles.CheckHourlyLoad(3) 20 idles.CheckHourlyLoad(2) 21 idles.CheckHourlyLoad(4) 22 } 23 24 t.Log(idles.TestMinLoadHours()) 25 for h, v := range idles.TestHourlyLoadMap() { 26 t.Log(types.String(h)+":", v.Avg) 27 } 28 } 29 30 func TestRun(t *testing.T) { 31 idles.TestSetMinLoadHours([]int{0, time.Now().Hour()}) 32 idles.Run(func() { 33 t.Log("run once") 34 }) 35 } 36 37 func TestRunTicker(t *testing.T) { 38 if !testutils.IsSingleTesting() { 39 return 40 } 41 42 var ticker = time.NewTicker(10 * time.Second) 43 idles.RunTicker(ticker, func() { 44 t.Log(timeutil.Format("H:i:s"), "run once") 45 }) 46 } 47 48 func TestIsMinHour(t *testing.T) { 49 t.Log(idles.IsMinHour()) 50 }