Skip to content

Commit

Permalink
bug fix: jobs not being scheduled after timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
z4yx committed Jun 4, 2020
1 parent d8963c9 commit b5d2a0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 0 additions & 1 deletion worker/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func (m *mirrorJob) Run(managerChan chan<- jobMessage, semaphore chan empty) err
logger.Debug("syncing done")
case <-time.After(timeout):
logger.Notice("provider timeout")
stopASAP = true
termErr = provider.Terminate()
syncErr = fmt.Errorf("%s timeout after %v", m.Name(), timeout)
case <-kill:
Expand Down
25 changes: 24 additions & 1 deletion worker/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ echo $TUNASYNC_WORKING_DIR
})
})


Convey("When a job timed out", func(ctx C) {
scriptContent := `#!/bin/bash
echo $TUNASYNC_WORKING_DIR
Expand Down Expand Up @@ -371,6 +370,30 @@ echo $TUNASYNC_WORKING_DIR
job.ctrlChan <- jobDisable
<-job.disabled
})

Convey("It should be retried", func(ctx C) {
go job.Run(managerChan, semaphore)
job.ctrlChan <- jobStart
time.Sleep(1 * time.Second)
msg := <-managerChan
So(msg.status, ShouldEqual, PreSyncing)

for i := 0; i < defaultMaxRetry; i++ {
msg = <-managerChan
So(msg.status, ShouldEqual, Syncing)

job.ctrlChan <- jobStart // should be ignored

msg = <-managerChan
So(msg.status, ShouldEqual, Failed)
So(msg.msg, ShouldContainSubstring, "timeout after")
// re-schedule after last try
So(msg.schedule, ShouldEqual, i == defaultMaxRetry-1)
}

job.ctrlChan <- jobDisable
<-job.disabled
})
})
})

Expand Down

0 comments on commit b5d2a0a

Please sign in to comment.