From 58f94f047057db61f30c7aaa42f2f307c0c97611 Mon Sep 17 00:00:00 2001 From: Jan Dubsky Date: Thu, 29 Sep 2022 22:53:23 +0200 Subject: [PATCH] Add test for release after acquire --- pool_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pool_test.go b/pool_test.go index 9e22d37..012bf09 100644 --- a/pool_test.go +++ b/pool_test.go @@ -1170,7 +1170,6 @@ func BenchmarkPoolAcquireAndRelease(b *testing.B) { }) } } - func benchmarkPool[T any](t testing.TB) *puddle.Pool[T] { cfg := puddle.Config[T]{ MaxSize: 1, @@ -1206,6 +1205,27 @@ func releaser[T any](t testing.TB) chan<- *puddle.Resource[T] { return workChan } +func TestReleaseAfterAcquire(t *testing.T) { + const cnt = 100000 + + r := require.New(t) + ctx := context.Background() + pool := benchmarkPool[int32](t) + releaseChan := releaser[int32](t) + + res, err := pool.Acquire(ctx) + r.NoError(err) + // We need to release the last connection. Otherwise the pool.Close() + // method will block and this function will never return. + defer func() { res.Release() }() + + for i := 0; i < cnt; i++ { + releaseChan <- res + res, err = pool.Acquire(ctx) + r.NoError(err) + } +} + func BenchmarkAcquire_ReleaseAfterAcquire(b *testing.B) { r := require.New(b) ctx := context.Background()