/
task_runner_priv_test.go
63 lines (51 loc) · 1.51 KB
/
task_runner_priv_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
package task_runner
import (
"os"
"testing"
"time"
)
func TestStartTaskRunner(t *testing.T) {
no_worker := 3
runner := StartTaskRunner(no_worker, os.Stdout)
if len(runner.workerMap) != no_worker {
t.Errorf("Incorrect worker map len Expected: %d Found: %d",
no_worker, len(runner.workerMap))
}
if cap(runner.workerQueue) != no_worker {
t.Errorf("Incorrect worker queue cap Expected: %d Found: %d",
no_worker, cap(runner.workerQueue))
}
runner.Stop()
time.Sleep(time.Second * 5) // Give 5 secs to gracefully exit.
if ! runner.stopped {
t.Error("Task runner not stopped yet.")
}
}
func TestTaskRunner_CreateBufferedTaskRunner(t *testing.T) {
no_worker := 3
runner := StartTaskRunner(no_worker, os.Stdout)
// Currently only 1000 are supported.
// Override using env variable
task_chan := runner.CreateBufferedTaskRunner(1000000)
if task_chan != nil {
t.Errorf("Expected to fail instead returned channel of len %d",
cap(task_chan))
}
task_chan = runner.CreateBufferedTaskRunner(100)
if cap(task_chan) != 100 {
t.Errorf("Expected channel capacity: %d Found: %d",
100, cap(task_chan))
}
runner.Stop()
time.Sleep(time.Second * 5) // Give 5 secs to gracefully exit.
if ! runner.stopped {
t.Error("Task runner not stopped yet.")
}
runner2 := StartTaskRunner(no_worker, os.Stdout)
os.Setenv("OVERRIDE_QUEUE_SIZE", "1")
task_chan2 := runner2.CreateBufferedTaskRunner(1500)
if cap(task_chan2) != 1500 {
t.Errorf("Expected channel capacity: %d Found: %d",
1500, cap(task_chan2))
}
}