1
0
镜像自地址 https://github.com/tuna/tunasync.git 已同步 2025-12-07 06:56:47 +00:00

feature(worker): job schedule

这个提交包含在:
bigeagle
2016-04-24 20:23:44 +08:00
父节点 f31bcfbcc3
当前提交 b077db1d0b
共有 5 个文件被更改,包括 191 次插入33 次删除

50
worker/schedule_test.go 普通文件
查看文件

@@ -0,0 +1,50 @@
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 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)
})
})
}