forked from tuna/tunasync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule_test.go
68 lines (55 loc) · 1.56 KB
/
schedule_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package worker
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestSchedule(t *testing.T) {
Convey("MirrorJobSchedule should work", t, func(ctx C) {
schedule := newScheduleQueue()
Convey("When poping on empty schedule", func() {
job := schedule.Pop()
So(job, ShouldBeNil)
})
Convey("When adding some jobs", func() {
c := cmdConfig{
name: "schedule_test",
}
provider, _ := newCmdProvider(c)
job := newMirrorJob(provider)
sched := time.Now().Add(1 * time.Second)
schedule.AddJob(sched, job)
So(schedule.Pop(), ShouldBeNil)
time.Sleep(1200 * time.Millisecond)
So(schedule.Pop(), ShouldEqual, job)
})
Convey("When adding one job twice", func() {
c := cmdConfig{
name: "schedule_test",
}
provider, _ := newCmdProvider(c)
job := newMirrorJob(provider)
sched := time.Now().Add(1 * time.Second)
schedule.AddJob(sched, job)
schedule.AddJob(sched.Add(1*time.Second), job)
So(schedule.Pop(), ShouldBeNil)
time.Sleep(1200 * time.Millisecond)
So(schedule.Pop(), ShouldBeNil)
time.Sleep(1200 * time.Millisecond)
So(schedule.Pop(), ShouldEqual, job)
})
Convey("When removing jobs", func() {
c := cmdConfig{
name: "schedule_test",
}
provider, _ := newCmdProvider(c)
job := newMirrorJob(provider)
sched := time.Now().Add(1 * time.Second)
schedule.AddJob(sched, job)
So(schedule.Remove("something"), ShouldBeFalse)
So(schedule.Remove("schedule_test"), ShouldBeTrue)
time.Sleep(1200 * time.Millisecond)
So(schedule.Pop(), ShouldBeNil)
})
})
}