From 742a58164cb05c93b3244ab041f93d8cc53ce6cd Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 30 Sep 2017 09:21:59 +0300 Subject: [PATCH] Add test for receive big message payload --- commands.go | 5 +++-- pubsub_test.go | 16 ++++++++++++++++ race_test.go | 9 ++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index a3b90f1..c04b3c4 100644 --- a/commands.go +++ b/commands.go @@ -214,6 +214,7 @@ type Cmdable interface { ScriptKill() *StatusCmd ScriptLoad(script string) *StringCmd DebugObject(key string) *StringCmd + Publish(channel string, message interface{}) *IntCmd PubSubChannels(pattern string) *StringSliceCmd PubSubNumSub(channels ...string) *StringIntMapCmd PubSubNumPat() *IntCmd @@ -1880,8 +1881,8 @@ func (c *cmdable) DebugObject(key string) *StringCmd { //------------------------------------------------------------------------------ // Publish posts the message to the channel. -func (c *cmdable) Publish(channel, message string) *IntCmd { - cmd := NewIntCmd("PUBLISH", channel, message) +func (c *cmdable) Publish(channel string, message interface{}) *IntCmd { + cmd := NewIntCmd("publish", channel, message) c.process(cmd) return cmd } diff --git a/pubsub_test.go b/pubsub_test.go index 6fc04a1..6a85bd0 100644 --- a/pubsub_test.go +++ b/pubsub_test.go @@ -424,4 +424,20 @@ var _ = Describe("PubSub", func() { wg.Wait() }) + + It("handles big message payload", func() { + pubsub := client.Subscribe("mychannel") + defer pubsub.Close() + + ch := pubsub.Channel() + + bigVal := bigVal() + err := client.Publish("mychannel", bigVal).Err() + Expect(err).NotTo(HaveOccurred()) + + var msg *redis.Message + Eventually(ch).Should(Receive(&msg)) + Expect(msg.Channel).To(Equal("mychannel")) + Expect(msg.Payload).To(Equal(string(bigVal))) + }) }) diff --git a/race_test.go b/race_test.go index 5bcb076..1426408 100644 --- a/race_test.go +++ b/race_test.go @@ -105,7 +105,7 @@ var _ = Describe("races", func() { It("should handle big vals in Get", func() { C, N = 4, 100 - bigVal := bytes.Repeat([]byte{'*'}, 1<<17) // 128kb + bigVal := bigVal() err := client.Set("key", bigVal, 0).Err() Expect(err).NotTo(HaveOccurred()) @@ -126,8 +126,7 @@ var _ = Describe("races", func() { It("should handle big vals in Set", func() { C, N = 4, 100 - bigVal := bytes.Repeat([]byte{'*'}, 1<<17) // 128kb - + bigVal := bigVal() perform(C, func(id int) { for i := 0; i < N; i++ { err := client.Set("key", bigVal, 0).Err() @@ -245,3 +244,7 @@ var _ = Describe("races", func() { Expect(n).To(Equal(int64(N))) }) }) + +func bigVal() []byte { + return bytes.Repeat([]byte{'*'}, 1<<17) // 128kb +}