From 46dd7afbbf95205808592008813f24affa09aca9 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 8 Mar 2018 13:50:16 +0200 Subject: [PATCH] Add cluster race test --- race_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/race_test.go b/race_test.go index 789c8ba..acecf85 100644 --- a/race_test.go +++ b/race_test.go @@ -285,6 +285,53 @@ var _ = Describe("races", func() { }) }) +var _ = Describe("cluster races", func() { + var client *redis.ClusterClient + var C, N int + + BeforeEach(func() { + opt := redisClusterOptions() + client = cluster.clusterClient(opt) + + C, N = 10, 1000 + if testing.Short() { + C = 4 + N = 100 + } + }) + + AfterEach(func() { + err := client.Close() + Expect(err).NotTo(HaveOccurred()) + }) + + It("should echo", func() { + perform(C, func(id int) { + for i := 0; i < N; i++ { + msg := fmt.Sprintf("echo %d %d", id, i) + echo, err := client.Echo(msg).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(echo).To(Equal(msg)) + } + }) + }) + + It("should incr", func() { + key := "TestIncrFromGoroutines" + + perform(C, func(id int) { + for i := 0; i < N; i++ { + err := client.Incr(key).Err() + Expect(err).NotTo(HaveOccurred()) + } + }) + + val, err := client.Get(key).Int64() + Expect(err).NotTo(HaveOccurred()) + Expect(val).To(Equal(int64(C * N))) + }) +}) + func bigVal() []byte { return bytes.Repeat([]byte{'*'}, 1<<17) // 128kb }