Merge branch 'master' into v5-dev
This commit is contained in:
@@ -47,6 +47,32 @@ func TestParseConfigExtractsPoolArguments(t *testing.T) {
|
||||
assert.NotContains(t, config.ConnConfig.Config.RuntimeParams, "pool_min_conns")
|
||||
}
|
||||
|
||||
func TestConstructorIgnoresContext(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
|
||||
assert.NoError(t, err)
|
||||
var cancel func()
|
||||
config.BeforeConnect = func(context.Context, *pgx.ConnConfig) error {
|
||||
// cancel the query's context before we actually Dial to ensure the Dial's
|
||||
// context isn't cancelled
|
||||
cancel()
|
||||
return nil
|
||||
}
|
||||
|
||||
pool, err := pgxpool.NewWithConfig(context.Background(), config)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.EqualValues(t, 0, pool.Stat().TotalConns())
|
||||
|
||||
var ctx context.Context
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
_, err = pool.Exec(ctx, "SELECT 1")
|
||||
assert.ErrorIs(t, err, context.Canceled)
|
||||
assert.EqualValues(t, 1, pool.Stat().TotalConns())
|
||||
}
|
||||
|
||||
func TestConnectConfigRequiresConnConfigFromParseConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user