forked from mirror/redis
pubsub: add PSubscribe test. Updates #233.
This commit is contained in:
parent
d226168576
commit
1739cd9380
|
@ -244,7 +244,7 @@ func (c *PubSub) reconnect(reason error) {
|
||||||
}
|
}
|
||||||
if len(c.patterns) > 0 {
|
if len(c.patterns) > 0 {
|
||||||
if err := c.PSubscribe(c.patterns...); err != nil {
|
if err := c.PSubscribe(c.patterns...); err != nil {
|
||||||
log.Printf("redis: Subscribe failed: %s", err)
|
log.Printf("redis: PSubscribe failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,11 +255,7 @@ var _ = Describe("PubSub", func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should reconnect on ReceiveMessage error", func() {
|
expectReceiveMessage := func(pubsub *redis.PubSub) {
|
||||||
pubsub, err := client.Subscribe("mychannel")
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
defer pubsub.Close()
|
|
||||||
|
|
||||||
cn1, _, err := pubsub.Pool().Get()
|
cn1, _, err := pubsub.Pool().Get()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
cn1.SetNetConn(&badConn{
|
cn1.SetNetConn(&badConn{
|
||||||
|
@ -284,6 +280,22 @@ var _ = Describe("PubSub", func() {
|
||||||
Expect(msg.Payload).To(Equal("hello"))
|
Expect(msg.Payload).To(Equal("hello"))
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
It("Subscribe should reconnect on ReceiveMessage error", func() {
|
||||||
|
pubsub, err := client.Subscribe("mychannel")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
defer pubsub.Close()
|
||||||
|
|
||||||
|
expectReceiveMessage(pubsub)
|
||||||
|
})
|
||||||
|
|
||||||
|
It("PSubscribe should reconnect on ReceiveMessage error", func() {
|
||||||
|
pubsub, err := client.PSubscribe("mychannel")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
defer pubsub.Close()
|
||||||
|
|
||||||
|
expectReceiveMessage(pubsub)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should return on Close", func() {
|
It("should return on Close", func() {
|
||||||
|
|
Loading…
Reference in New Issue