1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-12 14:21:52 +03:00

add context cancelation support for blocking operations

This commit is contained in:
Pavlov Aleksey
2020-09-14 21:27:26 +03:00
committed by Vladimir Mihailenco
parent 4b9d6dfd40
commit eda1f9c6ad
2 changed files with 69 additions and 4 deletions

View File

@ -389,3 +389,28 @@ var _ = Describe("Client OnConnect", func() {
Expect(name).To(Equal("on_connect"))
})
})
var _ = Describe("Client context cancelation", func() {
var opt *redis.Options
var client *redis.Client
BeforeEach(func() {
opt = redisOptions()
opt.ReadTimeout = -1
opt.WriteTimeout = -1
client = redis.NewClient(opt)
})
AfterEach(func() {
Expect(client.Close()).NotTo(HaveOccurred())
})
It("Blocking operation cancelation", func() {
ctx, cancel := context.WithCancel(ctx)
cancel()
err := client.BLPop(ctx, 1*time.Second, "test").Err()
Expect(err).To(HaveOccurred())
Expect(err).To(BeIdenticalTo(context.Canceled))
})
})