-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunnel_test.go
More file actions
99 lines (80 loc) · 2.56 KB
/
funnel_test.go
File metadata and controls
99 lines (80 loc) · 2.56 KB
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
package disco
import(
"testing"
"time"
)
func TestFunnelIncomingChannel(t *testing.T) {
pool, _ := NewPool(2, 5, 1, time.Second * 200)
connection := pool.Get()
connection.AddJob("disco-test-queue", "this-is-the-payload", time.Second * 10)
connection.Close()
funnel := pool.NewFunnel("disco-test-queue")
select {
case job, ok := <- funnel.Incoming:
if !ok {
t.Fatal("I... I guess something is not ok")
}
if job.ID == "" {
t.Error("fetched jobs should always have ids")
}
if string(job.Payload) != "this-is-the-payload" {
t.Errorf("Expected payload does not match: '%v'", string(job.Payload))
}
case <- time.Tick(time.Second):
t.Error("Failed to fetch job in a timely manner")
}
}
func TestFunnelOutgoingChannel(t *testing.T) {
pool, _ := NewPool(2, 5, 1, time.Second * 200)
funnel := pool.NewFunnel("disco-test-queue")
funnel.Outgoing <- Job{Queue: "disco-test-queue", Payload: []byte("this-is-the-payload")}
select {
case job, ok := <- funnel.Incoming:
if !ok {
t.Fatal("I... I guess something is not ok")
}
if job.ID == "" {
t.Error("fetched jobs should always have ids")
}
if string(job.Payload) != "this-is-the-payload" {
t.Errorf("Expected payload does not match: '%v'", string(job.Payload))
}
case <- time.Tick(time.Second):
t.Error("Failed to fetch job in a timely manner")
}
}
func TestFunnelCloseBehaviour(t *testing.T) {
pool, _ := NewPool(2, 5, 1, time.Second * 200)
funnel := pool.NewFunnel("disco-test-queue")
defer func() {
if r := recover(); r != nil {
t.Error("We shouldn't be panicking under any circumstances.")
}
}()
funnel.Close()
select {
case funnel.Outgoing <- Job{Queue: "disco-test-queue", Payload: []byte("this-is-the-payload")}:
// NoOp, this should work.
case <- time.Tick(time.Second):
t.Error("we shouldnt be blocking the outgoing channel immediately after closing")
}
select {
case <- funnel.Incoming:
// NoOp, we want to fail gracefully at this point.
case <- time.Tick(time.Second):
t.Error("Closed funnels blocking external sends")
}
time.Sleep(time.Second * 2)
select {
case <- funnel.Incoming:
// NoOp, we want to fail gracefully at this point.
case <- time.Tick(time.Second):
t.Error("Closed funnels blocking reads")
}
select {
case funnel.Outgoing <- Job{Queue: "disco-test-queue", Payload: []byte("this-is-the-payload")}:
// NoOp, we want to fail gracefully at this point.
case <- time.Tick(time.Second):
t.Error("Closed funnels blocking sends")
}
}