(t *testing.T)
| 1372 | } |
| 1373 | |
| 1374 | func 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 |
| 1401 | func TestOpenTransactionsDiscarded(t *testing.T) { |
nothing calls this directly
no test coverage detected