mirror of
https://github.com/redis/go-redis.git
synced 2025-06-05 06:42:39 +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:
parent
bc70b52b42
commit
c149644da7
@ -387,4 +387,33 @@ var _ = Describe("race", func() {
|
||||
Expect(stats.WaitCount).To(Equal(uint32(1)))
|
||||
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)))
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user