ring: improve pipelining tests.

This commit is contained in:
Vladimir Mihailenco 2015-06-24 13:41:50 +03:00
parent d36559f9ce
commit fee949ecbf
1 changed files with 30 additions and 16 deletions

View File

@ -82,24 +82,38 @@ var _ = Describe("Redis ring", func() {
Expect(ringShard2.Info().Val()).To(ContainSubstring("keys=43")) Expect(ringShard2.Info().Val()).To(ContainSubstring("keys=43"))
}) })
It("supports pipelining", func() { Describe("pipelining", func() {
pipe := ring.Pipeline() It("uses both shards", func() {
for i := 0; i < 100; i++ { pipe := ring.Pipeline()
err := pipe.Set(fmt.Sprintf("key%d", i), "value", 0).Err() for i := 0; i < 100; i++ {
err := pipe.Set(fmt.Sprintf("key%d", i), "value", 0).Err()
Expect(err).NotTo(HaveOccurred())
}
cmds, err := pipe.Exec()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} Expect(cmds).To(HaveLen(100))
cmds, err := pipe.Exec() Expect(pipe.Close()).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred())
Expect(cmds).To(HaveLen(100))
Expect(pipe.Close()).NotTo(HaveOccurred())
for _, cmd := range cmds { for _, cmd := range cmds {
Expect(cmd.Err()).NotTo(HaveOccurred()) Expect(cmd.Err()).NotTo(HaveOccurred())
Expect(cmd.(*redis.StatusCmd).Val()).To(Equal("OK")) Expect(cmd.(*redis.StatusCmd).Val()).To(Equal("OK"))
} }
// Both shards should have some keys now. // Both shards should have some keys now.
Expect(ringShard1.Info().Val()).To(ContainSubstring("keys=57")) Expect(ringShard1.Info().Val()).To(ContainSubstring("keys=57"))
Expect(ringShard2.Info().Val()).To(ContainSubstring("keys=43")) Expect(ringShard2.Info().Val()).To(ContainSubstring("keys=43"))
})
It("is consistent", func() {
_, err := ring.Pipelined(func(pipe *redis.RingPipeline) error {
pipe.Set("mykey", "pipeline", 0)
return nil
})
Expect(err).NotTo(HaveOccurred())
val, err := ring.Get("mykey").Result()
Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal("pipeline"))
})
}) })
}) })