diff --git a/cluster_test.go b/cluster_test.go index 91b9e80e..324bd1ce 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -342,7 +342,8 @@ var _ = Describe("ClusterClient", func() { Expect(get.Val()).To(Equal(key + "_value")) ttl := cmds[(i*2)+1].(*redis.DurationCmd) - Expect(ttl.Val()).To(BeNumerically("~", time.Duration(i+1)*time.Hour, time.Second)) + dur := time.Duration(i+1) * time.Hour + Expect(ttl.Val()).To(BeNumerically("~", dur, 5*time.Second)) } }) @@ -476,9 +477,9 @@ var _ = Describe("ClusterClient", func() { Expect(err).NotTo(HaveOccurred()) for _, client := range cluster.masters() { - keys, err := client.Keys("*").Result() + size, err := client.DBSize().Result() Expect(err).NotTo(HaveOccurred()) - Expect(keys).To(HaveLen(0)) + Expect(size).To(Equal(int64(0))) } }) @@ -551,6 +552,9 @@ var _ = Describe("ClusterClient", func() { }) _ = client.ForEachSlave(func(slave *redis.Client) error { + Eventually(func() int64 { + return client.DBSize().Val() + }, 30*time.Second).Should(Equal(int64(0))) return slave.ClusterFailover().Err() }) }) @@ -717,11 +721,12 @@ var _ = Describe("ClusterClient timeout", func() { }) AfterEach(func() { - Eventually(func() error { - return client.ForEachNode(func(client *redis.Client) error { + client.ForEachNode(func(client *redis.Client) error { + Eventually(func() error { return client.Ping().Err() - }) - }, 2*pause).ShouldNot(HaveOccurred()) + }, 2*pause).ShouldNot(HaveOccurred()) + return nil + }) }) testTimeout() diff --git a/commands.go b/commands.go index 15f67a13..83b3824f 100644 --- a/commands.go +++ b/commands.go @@ -191,7 +191,7 @@ type Cmdable interface { ConfigGet(parameter string) *SliceCmd ConfigResetStat() *StatusCmd ConfigSet(parameter, value string) *StatusCmd - DbSize() *IntCmd + DBSize() *IntCmd FlushAll() *StatusCmd FlushAllAsync() *StatusCmd FlushDB() *StatusCmd @@ -1684,7 +1684,12 @@ func (c *cmdable) ConfigSet(parameter, value string) *StatusCmd { return cmd } +// Deperecated. Use DBSize instead. func (c *cmdable) DbSize() *IntCmd { + return c.DBSize() +} + +func (c *cmdable) DBSize() *IntCmd { cmd := NewIntCmd("dbsize") c.process(cmd) return cmd @@ -1704,9 +1709,7 @@ func (c *cmdable) FlushAllAsync() *StatusCmd { // Deprecated. Use FlushDB instead. func (c *cmdable) FlushDb() *StatusCmd { - cmd := NewStatusCmd("flushdb") - c.process(cmd) - return cmd + return c.FlushDB() } func (c *cmdable) FlushDB() *StatusCmd { diff --git a/commands_test.go b/commands_test.go index 81e0e4a8..4298cba6 100644 --- a/commands_test.go +++ b/commands_test.go @@ -139,10 +139,10 @@ var _ = Describe("Commands", func() { Expect(configSet.Val()).To(Equal("OK")) }) - It("should DbSize", func() { - dbSize := client.DbSize() - Expect(dbSize.Err()).NotTo(HaveOccurred()) - Expect(dbSize.Val()).To(Equal(int64(0))) + It("should DBSize", func() { + size, err := client.DBSize().Result() + Expect(err).NotTo(HaveOccurred()) + Expect(size).To(Equal(int64(0))) }) It("should Info", func() { diff --git a/pubsub_test.go b/pubsub_test.go index d44b1dd8..1d9dfcb9 100644 --- a/pubsub_test.go +++ b/pubsub_test.go @@ -400,8 +400,11 @@ var _ = Describe("PubSub", func() { pubsub := client.Subscribe() defer pubsub.Close() + var wg sync.WaitGroup + wg.Add(1) go func() { defer GinkgoRecover() + defer wg.Done() time.Sleep(2 * timeout) @@ -418,5 +421,7 @@ var _ = Describe("PubSub", func() { Expect(err).NotTo(HaveOccurred()) Expect(msg.Channel).To(Equal("mychannel")) Expect(msg.Payload).To(Equal("hello")) + + wg.Wait() }) })