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

feature(worker): job schedule

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

查看文件

@@ -63,11 +63,11 @@ func TestMirrorJob(t *testing.T) {
So(readedScriptContent, ShouldResemble, []byte(scriptContent))
Convey("If we let it run several times", func(ctx C) {
ctrlChan := make(chan ctrlAction)
managerChan := make(chan jobMessage, 10)
semaphore := make(chan empty, 1)
job := newMirrorJob(provider)
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
go job.Run(managerChan, semaphore)
for i := 0; i < 2; i++ {
msg := <-managerChan
So(msg.status, ShouldEqual, PreSyncing)
@@ -78,7 +78,7 @@ func TestMirrorJob(t *testing.T) {
loggedContent, err := ioutil.ReadFile(provider.LogFile())
So(err, ShouldBeNil)
So(string(loggedContent), ShouldEqual, exceptedOutput)
ctrlChan <- jobStart
job.ctrlChan <- jobStart
}
select {
case msg := <-managerChan:
@@ -92,7 +92,7 @@ func TestMirrorJob(t *testing.T) {
So(0, ShouldEqual, 1)
}
ctrlChan <- jobDisable
job.ctrlChan <- jobDisable
select {
case <-managerChan:
So(0, ShouldEqual, 1) // made this fail
@@ -112,12 +112,12 @@ echo $TUNASYNC_WORKING_DIR
err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
So(err, ShouldBeNil)
ctrlChan := make(chan ctrlAction)
managerChan := make(chan jobMessage, 10)
semaphore := make(chan empty, 1)
job := newMirrorJob(provider)
Convey("If we kill it", func(ctx C) {
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
go job.Run(managerChan, semaphore)
time.Sleep(1 * time.Second)
msg := <-managerChan
@@ -125,7 +125,7 @@ echo $TUNASYNC_WORKING_DIR
msg = <-managerChan
So(msg.status, ShouldEqual, Syncing)
ctrlChan <- jobStop
job.ctrlChan <- jobStop
msg = <-managerChan
So(msg.status, ShouldEqual, Failed)
@@ -134,11 +134,12 @@ echo $TUNASYNC_WORKING_DIR
loggedContent, err := ioutil.ReadFile(provider.LogFile())
So(err, ShouldBeNil)
So(string(loggedContent), ShouldEqual, exceptedOutput)
ctrlChan <- jobDisable
job.ctrlChan <- jobDisable
})
Convey("If we don't kill it", func(ctx C) {
go runMirrorJob(provider, ctrlChan, managerChan, semaphore)
go job.Run(managerChan, semaphore)
msg := <-managerChan
So(msg.status, ShouldEqual, PreSyncing)
msg = <-managerChan
@@ -154,7 +155,7 @@ echo $TUNASYNC_WORKING_DIR
loggedContent, err := ioutil.ReadFile(provider.LogFile())
So(err, ShouldBeNil)
So(string(loggedContent), ShouldEqual, exceptedOutput)
ctrlChan <- jobDisable
job.ctrlChan <- jobDisable
})
})