Conn.Close takes context
This commit is contained in:
+6
-1
@@ -2,6 +2,7 @@ package pool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgconn"
|
||||
"github.com/jackc/pgx"
|
||||
@@ -20,7 +21,11 @@ func Connect(ctx context.Context, connString string) (*Pool, error) {
|
||||
maxConnections := 5 // TODO - unhard-code
|
||||
p.p = puddle.NewPool(
|
||||
func(ctx context.Context) (interface{}, error) { return pgx.Connect(ctx, connString) },
|
||||
func(value interface{}) { value.(*pgx.Conn).Close() },
|
||||
func(value interface{}) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
value.(*pgx.Conn).Close(ctx)
|
||||
cancel()
|
||||
},
|
||||
maxConnections)
|
||||
|
||||
// Initially establish one connection
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ func TestConnReleaseDestroysClosedConn(t *testing.T) {
|
||||
c, err := pool.Acquire(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
c.Conn().Close()
|
||||
c.Conn().Close(ctx)
|
||||
|
||||
assert.Equal(t, 1, pool.Stat().TotalConns())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user