-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs_test.go
101 lines (95 loc) · 1.95 KB
/
jobs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"testing"
)
func TestJobWithNoDependenciesRuns(t *testing.T) {
success := make(chan bool)
job_run := false
job := NewJob()
job.AddListener(success)
job.SetProcess(func() bool {
job_run = true
return true
})
if !(<-success) {
t.Errorf("Job should have returned true")
}
if !job_run {
t.Errorf("Job should actually have been run")
}
}
func TestOutputWithSingleDependency(t *testing.T) {
success := make(chan bool)
job1_run := false
job2_run := false
job1 := NewJob()
job2 := NewJob()
job2.AddDependency(job1)
job2.AddListener(success)
job1.SetProcess(func() bool {
job1_run = true
return true
})
job2.SetProcess(func() bool {
job2_run = true
return true
})
if !(<-success) {
t.Errorf("Job should have returned true")
}
if !(job1_run && job2_run) {
t.Errorf("Job should actually have been run")
}
}
func TestChainedJobs(t *testing.T) {
success := make(chan bool)
job1 := NewJob()
job2 := NewJob()
job3 := NewJob()
job2.AddDependency(job1)
job3.AddDependency(job2)
job3.AddDependency(job1)
job3.AddListener(success)
job1.SetProcess(func() bool { return true })
job2.SetProcess(func() bool { return true })
job3.SetProcess(func() bool { return true })
if !(<-success) {
t.Errorf("Job should have returned true")
}
}
func TestJobsAfterFailingJobDontRun(t *testing.T) {
success := make(chan bool)
job1run := false
job2run := false
job3run := false
job1 := NewJob()
job2 := NewJob()
job3 := NewJob()
job2.AddDependency(job1)
job3.AddDependency(job2)
job3.AddListener(success)
job1.SetProcess(func() bool {
job1run = true
return true
})
job2.SetProcess(func() bool {
job2run = true
return false
})
job3.SetProcess(func() bool {
job3run = true
return true
})
if <-success {
t.Errorf("Job should have returned false")
}
if !job1run {
t.Errorf("Job 1 should have run")
}
if !job2run {
t.Errorf("Job 2 should have run")
}
if job3run {
t.Errorf("Job 3 should not have run")
}
}