Skip to content

Commit 0868d7a

Browse files
committed
Add tests for pg_wal_replay_wait() errors
Improve test coverage for pg_wal_replay_wait() procedure by adding test cases when it errors out.
1 parent 3ac3ec5 commit 0868d7a

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/test/recovery/t/043_wal_replay_wait.pl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,46 @@
7777
ok( $stderr =~ /timed out while waiting for target LSN/,
7878
"get timeout on waiting for unreachable LSN");
7979

80+
# 4. Check that pg_wal_replay_wait() triggers an error if called on primary,
81+
# within another function, or inside a transaction with an isolation level
82+
# higher than READ COMMITTED.
8083

81-
# 4. Also, check the scenario of multiple LSN waiters. We make 5 background
84+
$node_primary->psql(
85+
'postgres',
86+
"CALL pg_wal_replay_wait('${lsn3}');",
87+
stderr => \$stderr);
88+
ok( $stderr =~ /recovery is not in progress/,
89+
"get an error when running on the primary");
90+
91+
$node_standby1->psql(
92+
'postgres',
93+
"BEGIN ISOLATION LEVEL REPEATABLE READ; CALL pg_wal_replay_wait('${lsn3}');",
94+
stderr => \$stderr);
95+
ok( $stderr =~
96+
/pg_wal_replay_wait\(\) must be only called without an active or registered snapshot/,
97+
"get an error when running in a transaction with an isolation level higher than REPEATABLE READ"
98+
);
99+
100+
$node_primary->safe_psql(
101+
'postgres', qq[
102+
CREATE FUNCTION pg_wal_replay_wait_wrap(target_lsn pg_lsn) RETURNS void AS \$\$
103+
BEGIN
104+
CALL pg_wal_replay_wait(target_lsn);
105+
END
106+
\$\$
107+
LANGUAGE plpgsql;
108+
]);
109+
110+
$node_primary->wait_for_catchup($node_standby1);
111+
$node_standby1->psql(
112+
'postgres',
113+
"SELECT pg_wal_replay_wait_wrap('${lsn3}');",
114+
stderr => \$stderr);
115+
ok( $stderr =~
116+
/pg_wal_replay_wait\(\) must be only called without an active or registered snapshot/,
117+
"get an error when running within another function");
118+
119+
# 5. Also, check the scenario of multiple LSN waiters. We make 5 background
82120
# psql sessions each waiting for a corresponding insertion. When waiting is
83121
# finished, stored procedures logs if there are visible as many rows as
84122
# should be.
@@ -124,7 +162,7 @@
124162

125163
ok(1, 'multiple LSN waiters reported consistent data');
126164

127-
# 5. Check that the standby promotion terminates the wait on LSN. Start
165+
# 6. Check that the standby promotion terminates the wait on LSN. Start
128166
# waiting for an unreachable LSN then promote. Check the log for the relevant
129167
# error message. Also, check that waiting for already replayed LSN doesn't
130168
# cause an error even after promotion.

0 commit comments

Comments
 (0)