mirror of
https://github.com/jackc/pgx.git
synced 2025-07-07 19:19:37 +00:00
Add test for rollback failure
This commit is contained in:
parent
710ddf7134
commit
9e495df1d5
20
tx_test.go
20
tx_test.go
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/jackc/pgconn"
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTransactionSuccessfulCommit(t *testing.T) {
|
||||
@ -188,6 +189,25 @@ func TestTransactionSuccessfulRollback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTransactionRollbackFailsClosesConnection(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||
defer closeConn(t, conn)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
tx, err := conn.Begin(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
cancel()
|
||||
|
||||
err = tx.Rollback(ctx)
|
||||
require.Error(t, err)
|
||||
|
||||
require.True(t, conn.IsClosed())
|
||||
}
|
||||
|
||||
func TestBeginIsoLevels(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user