From 1739cd9380173ef4f513f792cb0ddb0d9e5c20f0 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 31 Dec 2015 11:27:28 +0200 Subject: [PATCH] pubsub: add PSubscribe test. Updates #233. --- pubsub.go | 2 +- pubsub_test.go | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pubsub.go b/pubsub.go index 3ee00e88..031eb843 100644 --- a/pubsub.go +++ b/pubsub.go @@ -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) } } } diff --git a/pubsub_test.go b/pubsub_test.go index 64938203..bf940d47 100644 --- a/pubsub_test.go +++ b/pubsub_test.go @@ -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() {