2
0

Fix pipeline batch results not closing pipeline

when error occurs while reading directly from results instead of using
a callback.

https://github.com/jackc/pgx/issues/1578
This commit is contained in:
Jack Christensen
2023-04-20 20:58:04 -05:00
parent 67f2a41587
commit 09371981f9
3 changed files with 33 additions and 15 deletions
+22
View File
@@ -720,6 +720,28 @@ func TestTxSendBatchRollback(t *testing.T) {
})
}
// https://github.com/jackc/pgx/issues/1578
func TestSendBatchErrorWhileReadingResultsWithoutCallback(t *testing.T) {
t.Parallel()
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
batch := &pgx.Batch{}
batch.Queue("select 4 / $1::int", 0)
batchResult := conn.SendBatch(ctx, batch)
_, execErr := batchResult.Exec()
require.Error(t, execErr)
closeErr := batchResult.Close()
require.Equal(t, execErr, closeErr)
// Try to use the connection.
_, err := conn.Exec(ctx, "select 1")
require.NoError(t, err)
})
}
func TestConnBeginBatchDeferredError(t *testing.T) {
t.Parallel()