fix TestPoolBackgroundChecksMinConns and NewConnsCount
Previously it was checking TotalConns but that includes ConstructingConns. Instead it should directly check IdleConns so the next Acquire takes one of those and doesn't make a 3rd connection. The check against the context was also wrong which prevented this from timing out after 2 minutes. This also fixes a bug where NewConnsCount was not correctly counting connections created by Acquire directly. Fixes #1690
This commit is contained in:
committed by
Jack Christensen
parent
f90e86fd8d
commit
e665f74c99
+1
-1
@@ -199,6 +199,7 @@ func NewWithConfig(ctx context.Context, config *Config) (*Pool, error) {
|
||||
p.p, err = puddle.NewPool(
|
||||
&puddle.Config[*connResource]{
|
||||
Constructor: func(ctx context.Context) (*connResource, error) {
|
||||
atomic.AddInt64(&p.newConnsCount, 1)
|
||||
connConfig := p.config.ConnConfig.Copy()
|
||||
|
||||
// Connection will continue in background even if Acquire is canceled. Ensure that a connect won't hang forever.
|
||||
@@ -475,7 +476,6 @@ func (p *Pool) createIdleResources(parentCtx context.Context, targetResources in
|
||||
|
||||
for i := 0; i < targetResources; i++ {
|
||||
go func() {
|
||||
atomic.AddInt64(&p.newConnsCount, 1)
|
||||
err := p.p.CreateResource(ctx)
|
||||
// Ignore ErrNotAvailable since it means that the pool has become full since we started creating resource.
|
||||
if err == puddle.ErrNotAvailable {
|
||||
|
||||
Reference in New Issue
Block a user