Skip to content

Commit c149644

Browse files
LINKIWIndyakov
andauthored
Unit test for pool acquisition timeout (#3381)
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
1 parent bc70b52 commit c149644

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

internal/pool/pool_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,33 @@ var _ = Describe("race", func() {
387387
Expect(stats.WaitCount).To(Equal(uint32(1)))
388388
Expect(stats.WaitDurationNs).To(BeNumerically("~", time.Second.Nanoseconds(), 100*time.Millisecond.Nanoseconds()))
389389
})
390+
391+
It("timeout", func() {
392+
testPoolTimeout := 1 * time.Second
393+
opt := &pool.Options{
394+
Dialer: func(ctx context.Context) (net.Conn, error) {
395+
// Artificial delay to force pool timeout
396+
time.Sleep(3 * testPoolTimeout)
397+
398+
return &net.TCPConn{}, nil
399+
},
400+
PoolSize: 1,
401+
PoolTimeout: testPoolTimeout,
402+
}
403+
p := pool.NewConnPool(opt)
404+
405+
stats := p.Stats()
406+
Expect(stats.Timeouts).To(Equal(uint32(0)))
407+
408+
conn, err := p.Get(ctx)
409+
Expect(err).NotTo(HaveOccurred())
410+
_, err = p.Get(ctx)
411+
Expect(err).To(MatchError(pool.ErrPoolTimeout))
412+
p.Put(ctx, conn)
413+
conn, err = p.Get(ctx)
414+
Expect(err).NotTo(HaveOccurred())
415+
416+
stats = p.Stats()
417+
Expect(stats.Timeouts).To(Equal(uint32(1)))
418+
})
390419
})

0 commit comments

Comments
 (0)