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

Function TestDeallocateInAbortedTransaction

conn_test.go:620–653  ·  view source on GitHub ↗

https://github.com/jackc/pgx/pull/1795

(t *testing.T)

Source from the content-addressed store, hash-verified

618
619// https://github.com/jackc/pgx/pull/1795
620func TestDeallocateInAbortedTransaction(t *testing.T) {
621 t.Parallel()
622
623 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
624 defer cancel()
625
626 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
627 tx, err := conn.Begin(ctx)
628 require.NoError(t, err)
629
630 sql := "select $1::text"
631 sd, err := tx.Prepare(ctx, sql, sql)
632 require.NoError(t, err)
633 require.Equal(t, "stmt_2510cc7db17de3f42758a2a29c8b9ef8305d007b997ebdd6", sd.Name)
634
635 var s string
636 err = tx.QueryRow(ctx, sql, "hello").Scan(&s)
637 require.NoError(t, err)
638 require.Equal(t, "hello", s)
639
640 _, err = tx.Exec(ctx, "select 1/0") // abort transaction with divide by zero error
641 require.Error(t, err)
642
643 err = conn.Deallocate(ctx, sql)
644 require.NoError(t, err)
645
646 err = tx.Rollback(ctx)
647 require.NoError(t, err)
648
649 sd, err = conn.Prepare(ctx, sql, sql)
650 require.NoError(t, err)
651 require.Equal(t, "stmt_2510cc7db17de3f42758a2a29c8b9ef8305d007b997ebdd6", sd.Name)
652 })
653}
654
655func TestDeallocateMissingPreparedStatementStillClearsFromPreparedStatementMap(t *testing.T) {
656 t.Parallel()

Callers

nothing calls this directly

Calls 9

RunWithQueryExecModesFunction · 0.92
BeginMethod · 0.65
PrepareMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65
ExecMethod · 0.65
RollbackMethod · 0.65
ErrorMethod · 0.45
DeallocateMethod · 0.45

Tested by

no test coverage detected