1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

Close the conn on context timeout

This commit is contained in:
Vladimir Mihailenco
2020-12-06 11:05:42 +02:00
parent 43d9b98d48
commit 02ccf05ed0
4 changed files with 50 additions and 21 deletions

View File

@ -2,6 +2,7 @@ package redis_test
import (
"bytes"
"context"
"fmt"
"net"
"strconv"
@ -295,6 +296,25 @@ var _ = Describe("races", func() {
Expect(err).NotTo(HaveOccurred())
})
})
It("should abort on context timeout", func() {
opt := redisClusterOptions()
client := cluster.newClusterClient(ctx, opt)
ctx, cancel := context.WithCancel(context.Background())
wg := performAsync(C, func(_ int) {
_, err := client.XRead(ctx, &redis.XReadArgs{
Streams: []string{"test", "$"},
Block: 1 * time.Second,
}).Result()
Expect(err).To(Equal(context.Canceled))
})
time.Sleep(10 * time.Millisecond)
cancel()
wg.Wait()
})
})
var _ = Describe("cluster races", func() {