2
0

Add *Tx.AfterClose hook

ConnPool now implements its connection with Tx via this hook instead of
manipulating the internals of Tx.
This commit is contained in:
Jack Christensen
2016-02-13 11:06:44 -06:00
parent 0f7bf19387
commit e8dcf5b3ac
3 changed files with 60 additions and 7 deletions
+36
View File
@@ -3,6 +3,7 @@ package pgx_test
import (
"github.com/jackc/pgx"
"testing"
"time"
)
func TestTransactionSuccessfulCommit(t *testing.T) {
@@ -114,3 +115,38 @@ func TestBeginIso(t *testing.T) {
}
}
}
func TestTxAfterClose(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn)
tx, err := conn.Begin()
if err != nil {
t.Fatal(err)
}
var zeroTime, t1, t2 time.Time
tx.AfterClose(func(tx *pgx.Tx) {
t1 = time.Now()
})
tx.AfterClose(func(tx *pgx.Tx) {
t2 = time.Now()
})
tx.Rollback()
if t1 == zeroTime {
t.Error("First Tx.AfterClose callback not called")
}
if t2 == zeroTime {
t.Error("Second Tx.AfterClose callback not called")
}
if t1.After(t2) {
t.Error("AfterClose callbacks called out of order: %v, %v", t1, t2)
}
}