Skip to content

Commit

Permalink
Made ConnPoolAvailWaitTime public
Browse files Browse the repository at this point in the history
This is the amount of time we'll wait for a connection from the pool if
there's not one immediately available before considering opening a new
one.
  • Loading branch information
dustin committed Jan 8, 2014
1 parent a74c61d commit daa0d6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion conn_pool.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions conn_pool_test.go
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit daa0d6f

Please sign in to comment.