From 317e656da6ae12678c45668f0850e1cb5c5dda42 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Wed, 19 Aug 2026 11:59:34 +0200
Subject: [PATCH] test_aio: Fix broken error recovery assertions in 001_aio

The three error recovery checks in `test_handle()` used `qr/^|ok$/` to
look for the `ok` marker column in psql's output. That is an alternation
of `^` and `ok$`, and `^` matches every string, so the assertions passed
no matter what psql printed.

Spelling the regex correctly as `qr/^ok\|$/` exposed that the explicit
xact case was actually failing: its marker `SELECT` ran inside the
transaction that the preceding error had already aborted, so it failed
with "current transaction is aborted" instead of showing that an AIO
handle can be acquired again after an error. No statement can succeed in
an aborted transaction, so the recovery statement has to run after the
`ROLLBACK` that ends it, like the subxact case already does after its
`ROLLBACK TO SAVEPOINT`.

The subxact case had no marker column in its query at all, so add one
there, and use the same `SELECT 'ok', handle_get_release()` ordering in
all three checks.

This issue originally found on the pytest framework thread[1].

[1]: https://postgr.es/m/DKSSP47Y857Z.1FUU91WMDZWPZ%40jeltef.nl
---
 src/test/modules/test_aio/t/001_aio.pl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/test/modules/test_aio/t/001_aio.pl b/src/test/modules/test_aio/t/001_aio.pl
index 63cadd64c15..bb74c325376 100644
--- a/src/test/modules/test_aio/t/001_aio.pl
+++ b/src/test/modules/test_aio/t/001_aio.pl
@@ -239,7 +239,7 @@ sub test_handle
 		$psql,
 		"handle error recovery in implicit xact",
 		qq(SELECT handle_get_and_error(); SELECT 'ok', handle_get_release()),
-		qr/^|ok$/,
+		qr/^ok\|$/,
 		qr/ERROR.*as you command/);
 
 	# recover after error in implicit xact
@@ -247,8 +247,8 @@ sub test_handle
 		$io_method,
 		$psql,
 		"handle error recovery in explicit xact",
-		qq(BEGIN; SELECT handle_get_and_error(); SELECT handle_get_release(), 'ok'; COMMIT;),
-		qr/^|ok$/,
+		qq(BEGIN; SELECT handle_get_and_error(); ROLLBACK; SELECT 'ok', handle_get_release();),
+		qr/^ok\|$/,
 		qr/ERROR.*as you command/);
 
 	# recover after error in subtrans
@@ -256,8 +256,8 @@ sub test_handle
 		$io_method,
 		$psql,
 		"handle error recovery in explicit subxact",
-		qq(BEGIN; SAVEPOINT foo; SELECT handle_get_and_error(); ROLLBACK TO SAVEPOINT foo; SELECT handle_get_release(); ROLLBACK;),
-		qr/^|ok$/,
+		qq(BEGIN; SAVEPOINT foo; SELECT handle_get_and_error(); ROLLBACK TO SAVEPOINT foo; SELECT 'ok', handle_get_release(); ROLLBACK;),
+		qr/^ok\|$/,
 		qr/ERROR.*as you command/);
 
 	$psql->quit();
-- 
2.54.0

