Add race test for BLPop

This commit is contained in:
Vladimir Mihailenco 2018-03-08 10:16:53 +02:00
parent 9133634a13
commit 11ca0e65c6
3 changed files with 33 additions and 3 deletions

View File

@ -788,8 +788,8 @@ var _ = Describe("ClusterClient timeout", func() {
Context("read/write timeout", func() { Context("read/write timeout", func() {
BeforeEach(func() { BeforeEach(func() {
opt := redisClusterOptions() opt := redisClusterOptions()
opt.ReadTimeout = 200 * time.Millisecond opt.ReadTimeout = 300 * time.Millisecond
opt.WriteTimeout = 200 * time.Millisecond opt.WriteTimeout = 300 * time.Millisecond
opt.MaxRedirects = 1 opt.MaxRedirects = 1
client = cluster.clusterClient(opt) client = cluster.clusterClient(opt)

View File

@ -142,7 +142,7 @@ func redisRingOptions() *redis.RingOptions {
} }
} }
func perform(n int, cbs ...func(int)) { func performAsync(n int, cbs ...func(int)) *sync.WaitGroup {
var wg sync.WaitGroup var wg sync.WaitGroup
for _, cb := range cbs { for _, cb := range cbs {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
@ -155,6 +155,11 @@ func perform(n int, cbs ...func(int)) {
}(cb, i) }(cb, i)
} }
} }
return &wg
}
func perform(n int, cbs ...func(int)) {
wg := performAsync(n, cbs...)
wg.Wait() wg.Wait()
} }

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net" "net"
"strconv" "strconv"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -258,6 +259,30 @@ var _ = Describe("races", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(N))) Expect(n).To(Equal(int64(N)))
}) })
It("should BLPop", func() {
var received uint32
wg := performAsync(C, func(id int) {
for {
v, err := client.BLPop(3*time.Second, "list").Result()
if err != nil {
break
}
Expect(v).To(Equal([]string{"list", "hello"}))
atomic.AddUint32(&received, 1)
}
})
perform(C, func(id int) {
for i := 0; i < N; i++ {
err := client.LPush("list", "hello").Err()
Expect(err).NotTo(HaveOccurred())
}
})
wg.Wait()
Expect(received).To(Equal(uint32(C * N)))
})
}) })
func bigVal() []byte { func bigVal() []byte {