mirror of https://github.com/jackc/pgx.git
Merge branch 'master' into add-name
commit
9041885e3f
|
@ -12,6 +12,7 @@
|
|||
* Add "char" type support (Manni Wood)
|
||||
* Add NullOid type (Manni Wood)
|
||||
* Add json/jsonb binary support to allow use with CopyTo
|
||||
* Add named error ErrAcquireTimeout (Alexander Staubo)
|
||||
|
||||
# 2.9.0 (August 26, 2016)
|
||||
|
||||
|
|
|
@ -40,6 +40,9 @@ type ConnPoolStat struct {
|
|||
AvailableConnections int // unused live connections
|
||||
}
|
||||
|
||||
// ErrAcquireTimeout occurs when an attempt to acquire a connection times out.
|
||||
var ErrAcquireTimeout = errors.New("timeout acquiring connection from pool")
|
||||
|
||||
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
|
||||
// Connect directly.
|
||||
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) {
|
||||
|
@ -131,7 +134,7 @@ func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
|
|||
|
||||
// Make sure the deadline (if it is) has not passed yet
|
||||
if p.deadlinePassed(deadline) {
|
||||
return nil, errors.New("Timeout: Acquire connection timeout")
|
||||
return nil, ErrAcquireTimeout
|
||||
}
|
||||
|
||||
// If there is a deadline then start a timeout timer
|
||||
|
@ -164,7 +167,7 @@ func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
|
|||
// Wait until there is an available connection OR room to create a new connection
|
||||
for len(p.availableConnections) == 0 && len(p.allConnections)+p.inProgressConnects == p.maxConnections {
|
||||
if p.deadlinePassed(deadline) {
|
||||
return nil, errors.New("Timeout: All connections in pool are busy")
|
||||
return nil, ErrAcquireTimeout
|
||||
}
|
||||
p.cond.Wait()
|
||||
}
|
||||
|
|
|
@ -276,8 +276,8 @@ func TestPoolWithAcquireTimeoutSet(t *testing.T) {
|
|||
// ... then try to consume 1 more. It should fail after a short timeout.
|
||||
_, timeTaken, err := acquireWithTimeTaken(pool)
|
||||
|
||||
if err == nil || err.Error() != "Timeout: All connections in pool are busy" {
|
||||
t.Fatalf("Expected error to be 'Timeout: All connections in pool are busy', instead it was '%v'", err)
|
||||
if err == nil || err != pgx.ErrAcquireTimeout {
|
||||
t.Fatalf("Expected error to be pgx.ErrAcquireTimeout, instead it was '%v'", err)
|
||||
}
|
||||
if timeTaken < connAllocTimeout {
|
||||
t.Fatalf("Expected connection allocation time to be at least %v, instead it was '%v'", connAllocTimeout, timeTaken)
|
||||
|
|
Loading…
Reference in New Issue