Skip to content

Commit

Permalink
Merge pull request redis#234 from go-redis/fix/psubscribe-test
Browse files Browse the repository at this point in the history
pubsub: add PSubscribe test. Updates redis#233.
  • Loading branch information
vmihailenco committed Dec 31, 2015
2 parents d226168 + 1739cd9 commit aa0a969
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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() {
Expand Down

0 comments on commit aa0a969

Please sign in to comment.