@@ -56,7 +56,7 @@ func TestPool(t *testing.T) {
5656 })
5757 t .Run ("WithLimit" , func (t * testing.T ) {
5858 p := New [* testItem , testItem ](rootCtx , WithLimit [* testItem , testItem ](1 ))
59- require .EqualValues (t , 1 , p .limit )
59+ require .EqualValues (t , 1 , p .config . limit )
6060 })
6161 t .Run ("WithCreateFunc" , func (t * testing.T ) {
6262 var newCounter int64
@@ -73,7 +73,7 @@ func TestPool(t *testing.T) {
7373 return nil
7474 })
7575 require .NoError (t , err )
76- require .EqualValues (t , p .limit , atomic .LoadInt64 (& newCounter ))
76+ require .EqualValues (t , p .config . limit , atomic .LoadInt64 (& newCounter ))
7777 })
7878 })
7979 t .Run ("Retry" , func (t * testing.T ) {
@@ -247,6 +247,9 @@ func TestPool(t *testing.T) {
247247 return v , nil
248248 }),
249249 )
250+ p .closeItem = func (ctx context.Context , item * testItem ) {
251+ _ = item .Close (ctx )
252+ }
250253 err := p .With (rootCtx , func (ctx context.Context , testItem * testItem ) error {
251254 if atomic .LoadInt64 (& newItems ) < 10 {
252255 return expErr
@@ -265,7 +268,11 @@ func TestPool(t *testing.T) {
265268 })
266269 t .Run ("Stress" , func (t * testing.T ) {
267270 xtest .TestManyTimes (t , func (t testing.TB ) {
268- p := New [* testItem , testItem ](rootCtx )
271+ trace := * defaultTrace
272+ trace .OnChange = func (info ChangeInfo ) {
273+ require .GreaterOrEqual (t , info .Limit , info .Idle )
274+ }
275+ p := New [* testItem , testItem ](rootCtx , WithTrace [* testItem , testItem ](& trace ))
269276 var wg sync.WaitGroup
270277 wg .Add (DefaultLimit * 2 + 1 )
271278 for range make ([]struct {}, DefaultLimit * 2 ) {
@@ -290,7 +297,12 @@ func TestPool(t *testing.T) {
290297 })
291298 t .Run ("ParallelCreation" , func (t * testing.T ) {
292299 xtest .TestManyTimes (t , func (t testing.TB ) {
293- p := New [* testItem , testItem ](rootCtx )
300+ trace := * defaultTrace
301+ trace .OnChange = func (info ChangeInfo ) {
302+ require .Equal (t , DefaultLimit , info .Limit )
303+ require .LessOrEqual (t , info .Idle , DefaultLimit )
304+ }
305+ p := New [* testItem , testItem ](rootCtx , WithTrace [* testItem , testItem ](& trace ))
294306 var wg sync.WaitGroup
295307 for range make ([]struct {}, DefaultLimit * 10 ) {
296308 wg .Add (1 )
@@ -303,15 +315,11 @@ func TestPool(t *testing.T) {
303315 t .Failed ()
304316 }
305317 stats := p .Stats ()
306- require .LessOrEqual (t , stats .Idle + stats . InUse , DefaultLimit )
318+ require .LessOrEqual (t , stats .Idle , DefaultLimit )
307319 }()
308320 }
309321
310322 wg .Wait ()
311- stats := p .Stats ()
312- require .Equal (t , DefaultLimit , stats .Limit )
313- require .Equal (t , 0 , stats .InUse )
314- require .LessOrEqual (t , stats .Idle , DefaultLimit )
315323 }, xtest .StopAfter (14 * time .Second ))
316324 })
317325}
0 commit comments