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

Function TestBeginTxBeginQuery

tx_test.go:376–394  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

374}
375
376func TestBeginTxBeginQuery(t *testing.T) {
377 t.Parallel()
378
379 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
380 defer cancel()
381
382 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
383 tx, err := conn.BeginTx(ctx, pgx.TxOptions{BeginQuery: "begin read only"})
384 require.NoError(t, err)
385 defer tx.Rollback(ctx)
386
387 var readOnly bool
388 conn.QueryRow(ctx, "select current_setting('transaction_read_only')::bool").Scan(&readOnly)
389 require.True(t, readOnly)
390
391 err = tx.Rollback(ctx)
392 require.NoError(t, err)
393 })
394}
395
396func TestTxNestedTransactionCommit(t *testing.T) {
397 t.Parallel()

Callers

nothing calls this directly

Calls 5

RunWithQueryExecModesFunction · 0.92
RollbackMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65
BeginTxMethod · 0.45

Tested by

no test coverage detected