Merge pull request #234 from go-redis/fix/psubscribe-test

pubsub: add PSubscribe test. Updates #233.
This commit is contained in:
Vladimir Mihailenco 2015-12-31 11:45:00 +02:00
commit aa0a9697d8
2 changed files with 18 additions and 6 deletions

View File

@ -244,7 +244,7 @@ func (c *PubSub) reconnect(reason error) {
}
if len(c.patterns) > 0 {
if err := c.PSubscribe(c.patterns...); err != nil {
log.Printf("redis: Subscribe failed: %s", err)
log.Printf("redis: PSubscribe failed: %s", err)
}
}
}

View File

@ -255,11 +255,7 @@ var _ = Describe("PubSub", func() {
wg.Wait()
})
It("should reconnect on ReceiveMessage error", func() {
pubsub, err := client.Subscribe("mychannel")
Expect(err).NotTo(HaveOccurred())
defer pubsub.Close()
expectReceiveMessage := func(pubsub *redis.PubSub) {
cn1, _, err := pubsub.Pool().Get()
Expect(err).NotTo(HaveOccurred())
cn1.SetNetConn(&badConn{
@ -284,6 +280,22 @@ var _ = Describe("PubSub", func() {
Expect(msg.Payload).To(Equal("hello"))
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() {