Add test for release after acquire
This commit is contained in:
committed by
Jack Christensen
parent
4fbc609092
commit
58f94f0470
+21
-1
@@ -1170,7 +1170,6 @@ func BenchmarkPoolAcquireAndRelease(b *testing.B) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkPool[T any](t testing.TB) *puddle.Pool[T] {
|
func benchmarkPool[T any](t testing.TB) *puddle.Pool[T] {
|
||||||
cfg := puddle.Config[T]{
|
cfg := puddle.Config[T]{
|
||||||
MaxSize: 1,
|
MaxSize: 1,
|
||||||
@@ -1206,6 +1205,27 @@ func releaser[T any](t testing.TB) chan<- *puddle.Resource[T] {
|
|||||||
return workChan
|
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) {
|
func BenchmarkAcquire_ReleaseAfterAcquire(b *testing.B) {
|
||||||
r := require.New(b)
|
r := require.New(b)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|||||||
Reference in New Issue
Block a user