MCPcopy
hub / github.com/jackc/pgx / TestOptionShouldPing_HookCalledOnReuse

Function TestOptionShouldPing_HookCalledOnReuse

stdlib/sql_test.go:1374–1398  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1372}
1373
1374func TestOptionShouldPing_HookCalledOnReuse(t *testing.T) {
1375 hookCalled := false
1376
1377 db := openDB(t,
1378 stdlib.OptionShouldPing(func(context.Context, stdlib.ShouldPingParams) bool {
1379 hookCalled = true
1380 // Return false to avoid relying on actual ping behavior.
1381 return false
1382 }),
1383 )
1384 defer closeDB(t, db)
1385
1386 // Ensure reuse (so ResetSession runs)
1387 db.SetMaxOpenConns(1)
1388 db.SetMaxIdleConns(1)
1389
1390 // Establish the connection
1391 require.NoError(t, db.Ping())
1392
1393 // Reuse the connection -> should trigger ResetSession -> ShouldPing
1394 _, err := db.Exec("select 1")
1395 require.NoError(t, err)
1396
1397 require.True(t, hookCalled, "hook should be called on reuse")
1398}
1399
1400// https://github.com/jackc/pgx/pull/2481
1401func TestOpenTransactionsDiscarded(t *testing.T) {

Callers

nothing calls this directly

Calls 5

OptionShouldPingFunction · 0.92
openDBFunction · 0.85
closeDBFunction · 0.85
ExecMethod · 0.65
PingMethod · 0.45

Tested by

no test coverage detected