Skip to content

Commit

Permalink
Add cluster race test
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 8, 2018
1 parent 396e13a commit 46dd7af
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 46dd7af

Please sign in to comment.