-
Notifications
You must be signed in to change notification settings - Fork 2
/
worker_test.go
33 lines (27 loc) · 712 Bytes
/
worker_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
package main
import (
"io/ioutil"
"testing"
"time"
)
func TestRunJobSendingToWorkerIdlingChannel(t *testing.T) {
jobsChannel := make(chan *TestJob)
reportsChannel := make(chan *TestJob)
workerIdlingChannel := make(chan bool)
worker := NewWorker(jobsChannel, reportsChannel, workerIdlingChannel, &Project{})
worker.logger = Logger{"", ioutil.Discard}
workerIdling := false
go func() {
jobsChannel <- &TestJob{Command: "ls"}
}()
go worker.RunJob()
// Read workerIdling or timeout after 1 second
timer := time.NewTimer(time.Second * 1).C
select {
case <-timer:
case workerIdling = <-workerIdlingChannel:
}
if !workerIdling {
t.Error("It should send true to worker idling channel")
}
}