56 lines
954 B
Go
56 lines
954 B
Go
package scheduler
|
|
|
|
import (
|
|
"log"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestScheduler(t *testing.T) {
|
|
s := Scheduler{}
|
|
s.Start()
|
|
s.NewSchedule("1111", 3, callback)
|
|
time.Sleep(time.Second * 10)
|
|
s.RemoveSchedule("1111")
|
|
|
|
time.Sleep(time.Second * 3)
|
|
s.Stop()
|
|
}
|
|
|
|
func TestMassiveSchedule(t *testing.T) {
|
|
s := Scheduler{}
|
|
s.Start()
|
|
|
|
for i := 0; i < 9999; i++ {
|
|
s.NewSchedule(string(i), 5, test)
|
|
}
|
|
s.NewSchedule("#######################", 5, test)
|
|
time.Sleep(time.Second * 10)
|
|
|
|
s.NewSchedule("#######################", 1, test)
|
|
time.Sleep(time.Second * 100)
|
|
}
|
|
|
|
func callback(id string) {
|
|
log.Println(id)
|
|
}
|
|
|
|
func test(id string) {
|
|
if id == "#######################" {
|
|
log.Println(id)
|
|
}
|
|
}
|
|
|
|
func TestSchedulerStopStart(t *testing.T) {
|
|
s := Scheduler{}
|
|
s.Start()
|
|
s.NewSchedule("1111", 3, callback)
|
|
time.Sleep(time.Second * 10)
|
|
s.StopSchedule("1111")
|
|
time.Sleep(time.Second * 5)
|
|
s.StartSchedule("1111")
|
|
|
|
time.Sleep(time.Second * 10)
|
|
s.Stop()
|
|
}
|