2
0

Conn.Close takes context

This commit is contained in:
Jack Christensen
2019-04-10 14:56:14 -05:00
parent 2f948c5249
commit 3e87a8b363
6 changed files with 15 additions and 10 deletions
+6 -1
View File
@@ -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
View File
@@ -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())