2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-01 08:30:49 +00:00

worker: fix tests

The test failed on Windows, probably because the machine used for CI was
too slow. The new test doesn't depend on timing any more.
This commit is contained in:
Alexander Neumann 2016-02-21 00:04:52 +01:00
parent 482fc9f51d
commit 21a99397ff

View File

@ -92,10 +92,17 @@ func TestPoolErrors(t *testing.T) {
var errCancelled = errors.New("cancelled")
type Job struct {
suc chan struct{}
d time.Duration
}
func wait(job worker.Job, done <-chan struct{}) (interface{}, error) {
d := job.Data.(time.Duration)
j := job.Data.(Job)
select {
case <-time.After(d):
case j.suc <- struct{}{}:
return time.Now(), nil
case <-time.After(j.d):
return time.Now(), nil
case <-done:
return nil, errCancelled
@ -105,11 +112,12 @@ func wait(job worker.Job, done <-chan struct{}) (interface{}, error) {
func TestPoolCancel(t *testing.T) {
jobCh, resCh, p := newBufferedPool(20, concurrency, wait)
suc := make(chan struct{}, 1)
for i := 0; i < 20; i++ {
jobCh <- worker.Job{Data: 10 * time.Millisecond}
jobCh <- worker.Job{Data: Job{suc: suc, d: time.Second}}
}
time.Sleep(20 * time.Millisecond)
<-suc
p.Cancel()
p.Wait()