util-go/time/scheduler/scheduler_test.go

42 lines
855 B
Go
Raw Normal View History

2018-04-28 12:39:55 +00:00
package scheduler_test
import (
"log"
"testing"
"time"
"git.loafle.net/overflow/probe/service/scheduler"
"git.loafle.net/overflow/probe/service/scheduler/storage"
)
func TestDiscoverPort(t *testing.T) {
_storage := storage.NewMemoryStorage()
s := scheduler.New(_storage)
// Start a task with arguments
tID1, err := s.RunEvery(1*time.Second, TaskWithArgs, "Hello from recurring task 1")
if err != nil {
log.Fatal(err)
}
// Start the same task as above with a different argument
_, err = s.RunEvery(4*time.Second, TaskWithArgs, "Hello from recurring task 2")
if err != nil {
log.Fatal(err)
}
s.Start()
time.Sleep(4 * time.Second)
s.Cancel(tID1)
s.Wait()
}
func TaskWithoutArgs() {
log.Println("TaskWithoutArgs is executed")
}
func TaskWithArgs(message string) {
log.Println("TaskWithArgs is executed. message:", message)
}