From 5d67a5b2f37423e69f3a71d351feae349aaf25a9 Mon Sep 17 00:00:00 2001
From: alterego655 <824662526@qq.com>
Date: Fri, 17 Apr 2026 20:08:59 +0800
Subject: [PATCH v1] test: merge wrapper DDL and catchup in wait_for_lsn TAP

Create the PL/pgSQL function and procedure for the top-level WAIT FOR
checks in a single transaction, then wait once for standby replay before
running both tests.

This avoids an extra 'wait_for_catchup()' on the delayed standby without
changing the test coverage.
---
 src/test/recovery/t/049_wait_for_lsn.pl | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/test/recovery/t/049_wait_for_lsn.pl b/src/test/recovery/t/049_wait_for_lsn.pl
index 8358c57f7b7..11adcda1e9a 100644
--- a/src/test/recovery/t/049_wait_for_lsn.pl
+++ b/src/test/recovery/t/049_wait_for_lsn.pl
@@ -208,18 +208,7 @@ CREATE FUNCTION pg_wal_replay_wait_wrap(target_lsn pg_lsn) RETURNS void AS \$\$
   END
 \$\$
 LANGUAGE plpgsql;
-]);
-
-$node_primary->wait_for_catchup($node_standby);
-$node_standby->psql(
-	'postgres',
-	"SELECT pg_wal_replay_wait_wrap('${lsn3}');",
-	stderr => \$stderr);
-ok($stderr =~ /WAIT FOR can only be executed as a top-level statement/,
-	"get an error when running within a function");
 
-$node_primary->safe_psql(
-	'postgres', qq[
 CREATE PROCEDURE pg_wal_replay_wait_proc(target_lsn pg_lsn) AS \$\$
   BEGIN
     EXECUTE format('WAIT FOR LSN %L;', target_lsn);
@@ -229,6 +218,13 @@ LANGUAGE plpgsql;
 ]);
 
 $node_primary->wait_for_catchup($node_standby);
+$node_standby->psql(
+	'postgres',
+	"SELECT pg_wal_replay_wait_wrap('${lsn3}');",
+	stderr => \$stderr);
+ok($stderr =~ /WAIT FOR can only be executed as a top-level statement/,
+	"get an error when running within a function");
+
 $node_standby->psql(
 	'postgres',
 	"CALL pg_wal_replay_wait_proc('${lsn3}');",
-- 
2.51.0

