diff --git a/conn_pool.go b/conn_pool.go index 2a88bba..582ab85 100644 --- a/conn_pool.go +++ b/conn_pool.go @@ -15,6 +15,11 @@ var errNoPool = errors.New("no pool") // Default timeout for retrieving a connection from the pool. var ConnPoolTimeout = time.Hour * 24 * 30 +// ConnPoolAvailWaitTime is the amount of time to wait for an existing +// connection from the pool before considering the creation of a new +// one. +var ConnPoolAvailWaitTime = time.Millisecond + type connectionPool struct { host string mkConn func(host string, ah AuthHandler) (*memcached.Client, error) @@ -75,7 +80,7 @@ func (cp *connectionPool) GetWithTimeout(d time.Duration) (*memcached.Client, er default: } - t := time.NewTimer(connPoolAvailTimer) + t := time.NewTimer(ConnPoolAvailWaitTime) defer t.Stop() // Try to grab an available connection within 1ms diff --git a/conn_pool_test.go b/conn_pool_test.go index 985cb6b..d3a463c 100644 --- a/conn_pool_test.go +++ b/conn_pool_test.go @@ -110,7 +110,7 @@ func TestConnPool(t *testing.T) { } func TestConnPoolSoonAvailable(t *testing.T) { - defer func(d time.Duration) { connPoolAvailTimer = d }(connPoolAvailTimer) + defer func(d time.Duration) { ConnPoolAvailWaitTime = d }(ConnPoolAvailWaitTime) cp := newConnectionPool("h", &basicAuth{}, 3, 4) cp.mkConn = testMkConn @@ -134,7 +134,7 @@ func TestConnPoolSoonAvailable(t *testing.T) { time.AfterFunc(time.Millisecond, func() { cp.Return(aClient) }) - connPoolAvailTimer = time.Second + ConnPoolAvailWaitTime = time.Second sc, err := cp.Get() if err != nil || sc != aClient {