From 42b2a72e66734819bb35dedacadb902ffcad72d5 Mon Sep 17 00:00:00 2001 From: monkey Date: Thu, 25 Feb 2021 17:41:44 +0800 Subject: [PATCH 1/2] fix unit test errors that may appear in pool_test.go /redis/pool_test.go:119 Expected: : 98 to equal: : 99 Signed-off-by: monkey --- pool_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pool_test.go b/pool_test.go index 781c5df9..d66ffdbf 100644 --- a/pool_test.go +++ b/pool_test.go @@ -17,7 +17,7 @@ var _ = Describe("pool", func() { opt := redisOptions() opt.MinIdleConns = 0 opt.MaxConnAge = 0 - opt.IdleTimeout = time.Second + opt.IdleTimeout = 2 * time.Second client = redis.NewClient(opt) }) @@ -135,7 +135,7 @@ var _ = Describe("pool", func() { StaleConns: 0, })) - time.Sleep(2 * time.Second) + time.Sleep(3 * time.Second) stats = client.PoolStats() Expect(stats).To(Equal(&redis.PoolStats{ From 7d2e85eff6dda673e4bbdf2479c30ae89be48915 Mon Sep 17 00:00:00 2001 From: monkey Date: Mon, 1 Mar 2021 16:45:35 +0800 Subject: [PATCH 2/2] only set opt.IdleTimeout in It("reuses connections") Signed-off-by: monkey --- pool_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pool_test.go b/pool_test.go index d66ffdbf..08acc6de 100644 --- a/pool_test.go +++ b/pool_test.go @@ -17,7 +17,7 @@ var _ = Describe("pool", func() { opt := redisOptions() opt.MinIdleConns = 0 opt.MaxConnAge = 0 - opt.IdleTimeout = 2 * time.Second + opt.IdleTimeout = time.Second client = redis.NewClient(opt) }) @@ -105,6 +105,13 @@ var _ = Describe("pool", func() { }) It("reuses connections", func() { + // explain: https://github.com/go-redis/redis/pull/1675 + opt := redisOptions() + opt.MinIdleConns = 0 + opt.MaxConnAge = 0 + opt.IdleTimeout = 2 * time.Second + client = redis.NewClient(opt) + for i := 0; i < 100; i++ { val, err := client.Ping(ctx).Result() Expect(err).NotTo(HaveOccurred()) @@ -135,7 +142,7 @@ var _ = Describe("pool", func() { StaleConns: 0, })) - time.Sleep(3 * time.Second) + time.Sleep(2 * time.Second) stats = client.PoolStats() Expect(stats).To(Equal(&redis.PoolStats{