mirror of
https://github.com/redis/go-redis.git
synced 2025-07-25 08:21:55 +03:00
Unit test for pool acquisition timeout (#3381)
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
This commit is contained in:
@ -387,4 +387,33 @@ var _ = Describe("race", func() {
|
|||||||
Expect(stats.WaitCount).To(Equal(uint32(1)))
|
Expect(stats.WaitCount).To(Equal(uint32(1)))
|
||||||
Expect(stats.WaitDurationNs).To(BeNumerically("~", time.Second.Nanoseconds(), 100*time.Millisecond.Nanoseconds()))
|
Expect(stats.WaitDurationNs).To(BeNumerically("~", time.Second.Nanoseconds(), 100*time.Millisecond.Nanoseconds()))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("timeout", func() {
|
||||||
|
testPoolTimeout := 1 * time.Second
|
||||||
|
opt := &pool.Options{
|
||||||
|
Dialer: func(ctx context.Context) (net.Conn, error) {
|
||||||
|
// Artificial delay to force pool timeout
|
||||||
|
time.Sleep(3 * testPoolTimeout)
|
||||||
|
|
||||||
|
return &net.TCPConn{}, nil
|
||||||
|
},
|
||||||
|
PoolSize: 1,
|
||||||
|
PoolTimeout: testPoolTimeout,
|
||||||
|
}
|
||||||
|
p := pool.NewConnPool(opt)
|
||||||
|
|
||||||
|
stats := p.Stats()
|
||||||
|
Expect(stats.Timeouts).To(Equal(uint32(0)))
|
||||||
|
|
||||||
|
conn, err := p.Get(ctx)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
_, err = p.Get(ctx)
|
||||||
|
Expect(err).To(MatchError(pool.ErrPoolTimeout))
|
||||||
|
p.Put(ctx, conn)
|
||||||
|
conn, err = p.Get(ctx)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
stats = p.Stats()
|
||||||
|
Expect(stats.Timeouts).To(Equal(uint32(1)))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user