-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatcher_test.go
61 lines (49 loc) · 1.16 KB
/
dispatcher_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
package multiplejobqueue
import (
"testing"
)
func TestGetDispatcher(t *testing.T) {
dispatcher := GetDispatcher()
if dispatcher == nil {
t.Errorf("dispatcher is nil")
}
}
func TestDispatcher_Dispatch_ReturnErrorIfQueuesWereNotInitialized(t *testing.T) {
job := &TestJob{}
dispatcher := GetDispatcher()
err := dispatcher.Dispatch(job)
if err == nil {
t.Errorf("error is not nill when internalQueues were not initialized")
}
}
func TestDispatcher_Dispatch_ReturnErrorIfQueueNotExist(t *testing.T) {
InitializeQueues(0)
job := &TestJob{}
dispatcher := GetDispatcher()
err := dispatcher.Dispatch(job, "no_existing_queue")
if err == nil {
t.Errorf("error is not nill when queue_not_exists")
}
}
func TestDispatcher_Dispatch(t *testing.T) {
queues := InitializeQueues(0)
job := &TestJob{}
go func(t *testing.T) {
for {
select {
case _ = <-queues.queues[defaultQueue].queue:
return
default:
t.Errorf("job not enqueued")
}
}
}(t)
dispatcher := GetDispatcher()
err := dispatcher.Dispatch(job, defaultQueue)
if err != nil {
t.Errorf(err.Error())
}
if queues.numJobs != 1 {
t.Errorf("numJobs property was not updated")
}
}