diff --git a/tx_test.go b/tx_test.go index 47880bb0..7a640995 100644 --- a/tx_test.go +++ b/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()