-
Notifications
You must be signed in to change notification settings - Fork 1
/
session_test.go
85 lines (66 loc) · 1.97 KB
/
session_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
package steadyrabbit_test
import (
"fmt"
"time"
"github.com/BackAged/steadyrabbit"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/streadway/amqp"
)
func formConfig() *steadyrabbit.Config {
return &steadyrabbit.Config{
URL: "amqp://localhost",
}
}
var _ = Describe("Session", func() {
Context("NewSession", func() {
It("should instantiates various internals", func() {
cnf := formConfig()
cnf.Consumer = &steadyrabbit.ConsumerConfig{
QueueConfig: &steadyrabbit.QueueConfig{
QueueDeclare: true,
QueueName: "session.queue",
},
}
s, err := steadyrabbit.NewSession(cnf, steadyrabbit.ConsumerSessionType)
Expect(err).To(BeNil())
Expect(s).ToNot(BeNil())
Expect(s.NotifyCloseChan).ToNot(BeNil())
Expect(s.GetChannel()).ToNot(BeNil())
Expect(s.GetDeliveryChannel()).ToNot(BeNil())
})
})
It("should start NotifyCloseChan watcher", func() {
cnf := formConfig()
cnf.Consumer = &steadyrabbit.ConsumerConfig{
QueueConfig: &steadyrabbit.QueueConfig{
QueueDeclare: true,
QueueName: "session.queue",
},
}
s, err := steadyrabbit.NewSession(cnf, steadyrabbit.ConsumerSessionType)
Expect(err).To(BeNil())
Expect(s).ToNot(BeNil())
oldChannel := s.GetChannel()
oldDeliveryChannel := s.GetDeliveryChannel()
oldNotifyCloseChan := s.NotifyCloseChan
// Write an error to the NotifyCloseChan
s.NotifyCloseChan <- &amqp.Error{
Code: 0,
Reason: "Test failure",
Server: false,
Recover: false,
}
time.Sleep(2 * time.Second)
// We should also get new channels
Expect(s.NotifyCloseChan).ToNot(BeNil())
Expect(oldNotifyCloseChan).ToNot(Equal(s.NotifyCloseChan))
fmt.Println("got notify close channel")
Expect(s.GetChannel()).ToNot(BeNil())
Expect(oldChannel).ToNot(Equal(s.GetChannel()))
fmt.Println("got channel")
Expect(s.GetDeliveryChannel()).ToNot(BeNil())
Expect(oldDeliveryChannel).ToNot(Equal(s.GetDeliveryChannel()))
fmt.Println("got delivery channel")
})
})