mirror of https://github.com/jackc/pgx.git
Merge branch 'MaerF0x0-master'
commit
ef9e5159bf
|
@ -43,6 +43,9 @@ type ConnPoolStat struct {
|
||||||
// ErrAcquireTimeout occurs when an attempt to acquire a connection times out.
|
// ErrAcquireTimeout occurs when an attempt to acquire a connection times out.
|
||||||
var ErrAcquireTimeout = errors.New("timeout acquiring connection from pool")
|
var ErrAcquireTimeout = errors.New("timeout acquiring connection from pool")
|
||||||
|
|
||||||
|
// ErrClosedPool occurs on an attempt to acquire a connection from a closed pool.
|
||||||
|
var ErrClosedPool = errors.New("cannot acquire from closed pool")
|
||||||
|
|
||||||
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
|
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
|
||||||
// Connect directly.
|
// Connect directly.
|
||||||
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) {
|
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) {
|
||||||
|
@ -108,7 +111,7 @@ func (p *ConnPool) deadlinePassed(deadline *time.Time) bool {
|
||||||
// acquire performs acquision assuming pool is already locked
|
// acquire performs acquision assuming pool is already locked
|
||||||
func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
|
func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
|
||||||
if p.closed {
|
if p.closed {
|
||||||
return nil, errors.New("cannot acquire from closed pool")
|
return nil, ErrClosedPool
|
||||||
}
|
}
|
||||||
|
|
||||||
// A connection is available
|
// A connection is available
|
||||||
|
|
|
@ -315,6 +315,23 @@ func TestPoolWithoutAcquireTimeoutSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPoolErrClosedPool(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
pool := createConnPool(t, 1)
|
||||||
|
// Intentionaly close the pool now so we can test ErrClosedPool
|
||||||
|
pool.Close()
|
||||||
|
|
||||||
|
c, err := pool.Acquire()
|
||||||
|
if c != nil {
|
||||||
|
t.Fatalf("Expected acquired connection to be nil, instead it was '%v'", c)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil || err != pgx.ErrClosedPool {
|
||||||
|
t.Fatalf("Expected error to be pgx.ErrClosedPool, instead it was '%v'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPoolReleaseWithTransactions(t *testing.T) {
|
func TestPoolReleaseWithTransactions(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue