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

Function TestConnDeallocateSucceedsInAbortedTransaction

pgconn/pgconn_test.go:943–980  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

941}
942
943func TestConnDeallocateSucceedsInAbortedTransaction(t *testing.T) {
944 t.Parallel()
945
946 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
947 defer cancel()
948
949 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
950 require.NoError(t, err)
951 defer closeConn(t, pgConn)
952
953 err = pgConn.Exec(ctx, "begin").Close()
954 require.NoError(t, err)
955
956 _, err = pgConn.Prepare(ctx, "ps1", "select 1", nil)
957 require.NoError(t, err)
958
959 _, err = pgConn.ExecPrepared(ctx, "ps1", nil, nil, nil).Close()
960 require.NoError(t, err)
961
962 err = pgConn.Exec(ctx, "select 1/0").Close() // break transaction with divide by 0 error
963 require.Error(t, err)
964 var pgErr *pgconn.PgError
965 require.ErrorAs(t, err, &pgErr)
966 require.Equal(t, "22012", pgErr.Code)
967
968 err = pgConn.Deallocate(ctx, "ps1")
969 require.NoError(t, err)
970
971 err = pgConn.Exec(ctx, "rollback").Close()
972 require.NoError(t, err)
973
974 _, err = pgConn.ExecPrepared(ctx, "ps1", nil, nil, nil).Close()
975 require.Error(t, err)
976 require.ErrorAs(t, err, &pgErr)
977 require.Equal(t, "26000", pgErr.Code)
978
979 ensureConnValid(t, pgConn)
980}
981
982func TestConnDeallocateNonExistentStatementSucceeds(t *testing.T) {
983 t.Parallel()

Callers

nothing calls this directly

Calls 9

ConnectFunction · 0.92
closeConnFunction · 0.70
ensureConnValidFunction · 0.70
CloseMethod · 0.65
ExecMethod · 0.65
PrepareMethod · 0.65
ExecPreparedMethod · 0.45
ErrorMethod · 0.45
DeallocateMethod · 0.45

Tested by

no test coverage detected