镜像自地址
https://github.com/tuna/tunasync.git
已同步 2025-12-07 06:56:47 +00:00
feature(worker): job schedule
这个提交包含在:
50
worker/schedule_test.go
普通文件
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)
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户