MCPcopy
hub / github.com/tuna/tunasync / TestSchedule

Function TestSchedule

worker/schedule_test.go:10–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestSchedule(t *testing.T) {
11
12 Convey("MirrorJobSchedule should work", t, func(ctx C) {
13 schedule := newScheduleQueue()
14
15 Convey("When poping on empty schedule", func() {
16 job := schedule.Pop()
17 So(job, ShouldBeNil)
18 })
19
20 Convey("When adding some jobs", func() {
21 c := cmdConfig{
22 name: "schedule_test",
23 }
24 provider, _ := newCmdProvider(c)
25 job := newMirrorJob(provider)
26 sched := time.Now().Add(1 * time.Second)
27
28 schedule.AddJob(sched, job)
29 So(schedule.Pop(), ShouldBeNil)
30 time.Sleep(1200 * time.Millisecond)
31 So(schedule.Pop(), ShouldEqual, job)
32
33 })
34 Convey("When adding one job twice", func() {
35 c := cmdConfig{
36 name: "schedule_test",
37 }
38 provider, _ := newCmdProvider(c)
39 job := newMirrorJob(provider)
40 sched := time.Now().Add(1 * time.Second)
41
42 schedule.AddJob(sched, job)
43 schedule.AddJob(sched.Add(1*time.Second), job)
44
45 So(schedule.Pop(), ShouldBeNil)
46 time.Sleep(1200 * time.Millisecond)
47 So(schedule.Pop(), ShouldBeNil)
48 time.Sleep(1200 * time.Millisecond)
49 So(schedule.Pop(), ShouldEqual, job)
50
51 })
52 Convey("When removing jobs", func() {
53 c := cmdConfig{
54 name: "schedule_test",
55 }
56 provider, _ := newCmdProvider(c)
57 job := newMirrorJob(provider)
58 sched := time.Now().Add(1 * time.Second)
59
60 schedule.AddJob(sched, job)
61 So(schedule.Remove("something"), ShouldBeFalse)
62 So(schedule.Remove("schedule_test"), ShouldBeTrue)
63 time.Sleep(1200 * time.Millisecond)
64 So(schedule.Pop(), ShouldBeNil)
65 })
66
67 })

Callers

nothing calls this directly

Calls 6

newScheduleQueueFunction · 0.85
newCmdProviderFunction · 0.85
newMirrorJobFunction · 0.85
PopMethod · 0.80
AddJobMethod · 0.80
RemoveMethod · 0.80

Tested by

no test coverage detected