2
0

ResetSession hook is called before a connection is reused from pool for another query.

This commit is contained in:
Dmytro Haranzha
2021-05-13 15:02:22 +03:00
committed by Jack Christensen
parent 00feeaa5c9
commit cabb58cc40
2 changed files with 49 additions and 7 deletions
+23
View File
@@ -1202,3 +1202,26 @@ func TestRandomizeHostOrderFunc(t *testing.T) {
require.Fail(t, "did not get all hosts as primaries after many randomizations")
}
func TestResetSessionHookCalled(t *testing.T) {
var mockCalled bool
connConfig, err := pgx.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
require.NoError(t, err)
db := stdlib.OpenDB(*connConfig, stdlib.OptionResetSession(func(ctx context.Context, conn *pgx.Conn) error {
mockCalled = true
return nil
}))
defer closeDB(t, db)
err = db.Ping()
require.NoError(t, err)
err = db.Ping()
require.NoError(t, err)
require.True(t, mockCalled)
}