forked from robfig/cron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
exactschedule_test.go
42 lines (36 loc) · 1.13 KB
/
exactschedule_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cron
import (
"testing"
"time"
)
func TestTimeBeforeNow(t *testing.T) {
cron := newWithSeconds()
_, err := cron.ScheduleAtExactTime(time.Now().AddDate(-1, 0, 0), func() {
t.Error("Cron scheduled a job with a time in the past")
})
if err == nil {
t.Error("Expected an error when scheduling a job with a time in the past")
}
if err.Error() != "scheduleTime must be in the future" {
t.Errorf("Unexpected an error when scheduling a job with a time in the past: %v", err)
}
}
func TestExactScheduleRunsOnce(t *testing.T) {
cron := newWithSeconds()
cron.AddFunc("* * * * * *", func() {})
cron.ScheduleAtExactTime(time.Now().Add(1*time.Second), func() {})
cron.ScheduleAtExactTime(time.Now().Add(2*time.Second), func() {})
if len(cron.Entries()) != 3 {
t.Error("Expected cron entries to include 3 entries before starting cron")
}
cron.Start()
defer cron.Stop()
<-time.After(OneSecond)
if len(cron.Entries()) != 2 {
t.Error("Expected cron entries to include 2 entry after running cron")
}
<-time.After(OneSecond)
if len(cron.Entries()) != 1 {
t.Error("Expected cron entries to include 1 entry after running cron")
}
}