mirror of https://github.com/jackc/pgx.git
Add Pool.Reset()
parent
83670d675d
commit
0eda0109ca
|
@ -534,6 +534,15 @@ func (p *Pool) AcquireAllIdle(ctx context.Context) []*Conn {
|
||||||
return conns
|
return conns
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset closes all connections, but leaves the pool open. It is intended for use when an error is detected that would
|
||||||
|
// disrupt all connections (such as a network interruption or a server state change).
|
||||||
|
//
|
||||||
|
// It is safe to reset a pool while connections are checked out. Those connections will be closed when they are returned
|
||||||
|
// to the pool.
|
||||||
|
func (p *Pool) Reset() {
|
||||||
|
p.p.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
// Config returns a copy of config that was used to initialize this pool.
|
// Config returns a copy of config that was used to initialize this pool.
|
||||||
func (p *Pool) Config() *Config { return p.config.Copy() }
|
func (p *Pool) Config() *Config { return p.config.Copy() }
|
||||||
|
|
||||||
|
|
|
@ -349,6 +349,31 @@ func TestPoolAcquireAllIdle(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPoolReset(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db, err := pgxpool.New(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
conns := make([]*pgxpool.Conn, 3)
|
||||||
|
for i := range conns {
|
||||||
|
conns[i], err = db.Acquire(context.Background())
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Reset()
|
||||||
|
|
||||||
|
for _, c := range conns {
|
||||||
|
if c != nil {
|
||||||
|
c.Release()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitForReleaseToComplete()
|
||||||
|
|
||||||
|
require.EqualValues(t, 0, db.Stat().TotalConns())
|
||||||
|
}
|
||||||
|
|
||||||
func TestConnReleaseChecksMaxConnLifetime(t *testing.T) {
|
func TestConnReleaseChecksMaxConnLifetime(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue