Skip to content

Commit 5c77690

Browse files
committed
Improve wait logic in TAP tests for streaming replication.
Remove hard-wired sleep(2) delays in 001_stream_rep.pl in favor of using poll_query_until to check for the desired state to appear. In addition, add such a wait before the last test in the script, as it's possible to demonstrate failures there after upcoming improvements in pg_ctl. (We might end up adding polling before each of the get_slot_xmins calls in this script, but I feel no great need to do that until shown necessary.) In passing, clarify the description strings for some of the test cases. Michael Paquier and Craig Ringer, pursuant to a complaint from me Discussion: https://postgr.es/m/8962.1498425057@sss.pgh.pa.us
1 parent 5efccc1 commit 5c77690

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

src/test/recovery/t/001_stream_rep.pl

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ sub test_target_session_attrs
146146
"wal_receiver_status_interval = 1");
147147
$node_standby_2->restart;
148148

149+
# Wait for given condition on slot's pg_replication_slots row --- useful for
150+
# ensuring we've reached a quiescent condition for reading slot xmins
151+
sub wait_slot_xmins
152+
{
153+
my ($node, $slot_name, $check_expr) = @_;
154+
155+
$node->poll_query_until('postgres', qq[
156+
SELECT $check_expr
157+
FROM pg_catalog.pg_replication_slots
158+
WHERE slot_name = '$slot_name';
159+
]);
160+
}
161+
162+
# Fetch xmin columns from slot's pg_replication_slots row
149163
sub get_slot_xmins
150164
{
151165
my ($node, $slotname) = @_;
@@ -156,12 +170,12 @@ sub get_slot_xmins
156170
# There's no hot standby feedback and there are no logical slots on either peer
157171
# so xmin and catalog_xmin should be null on both slots.
158172
my ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
159-
is($xmin, '', 'non-cascaded slot xmin null with no hs_feedback');
160-
is($catalog_xmin, '', 'non-cascaded slot xmin null with no hs_feedback');
173+
is($xmin, '', 'xmin of non-cascaded slot null with no hs_feedback');
174+
is($catalog_xmin, '', 'catalog xmin of non-cascaded slot null with no hs_feedback');
161175

162176
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
163-
is($xmin, '', 'cascaded slot xmin null with no hs_feedback');
164-
is($catalog_xmin, '', 'cascaded slot xmin null with no hs_feedback');
177+
is($xmin, '', 'xmin of cascaded slot null with no hs_feedback');
178+
is($catalog_xmin, '', 'catalog xmin of cascaded slot null with no hs_feedback');
165179

166180
# Replication still works?
167181
$node_master->safe_psql('postgres', 'CREATE TABLE replayed(val integer);');
@@ -196,15 +210,18 @@ sub replay_check
196210
'ALTER SYSTEM SET hot_standby_feedback = on;');
197211
$node_standby_2->reload;
198212
replay_check();
199-
sleep(2);
213+
214+
wait_slot_xmins($node_master, $slotname_1,
215+
"xmin IS NOT NULL AND catalog_xmin IS NULL");
200216

201217
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
202-
isnt($xmin, '', 'non-cascaded slot xmin non-null with hs feedback');
203-
is($catalog_xmin, '', 'non-cascaded slot xmin still null with hs_feedback');
218+
isnt($xmin, '', 'xmin of non-cascaded slot non-null with hs feedback');
219+
is($catalog_xmin, '',
220+
'catalog xmin of non-cascaded slot still null with hs_feedback');
204221

205222
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
206-
isnt($xmin, '', 'cascaded slot xmin non-null with hs feedback');
207-
is($catalog_xmin, '', 'cascaded slot xmin still null with hs_feedback');
223+
isnt($xmin, '', 'xmin of cascaded slot non-null with hs feedback');
224+
is($catalog_xmin, '', 'catalog xmin of cascaded slot still null with hs_feedback');
208225

209226
note "doing some work to advance xmin";
210227
for my $i (10000 .. 11000)
@@ -216,15 +233,15 @@ sub replay_check
216233

217234
my ($xmin2, $catalog_xmin2) = get_slot_xmins($node_master, $slotname_1);
218235
note "new xmin $xmin2, old xmin $xmin";
219-
isnt($xmin2, $xmin, 'non-cascaded slot xmin with hs feedback has changed');
236+
isnt($xmin2, $xmin, 'xmin of non-cascaded slot with hs feedback has changed');
220237
is($catalog_xmin2, '',
221-
'non-cascaded slot xmin still null with hs_feedback unchanged');
238+
'catalog xmin of non-cascaded slot still null with hs_feedback unchanged');
222239

223240
($xmin2, $catalog_xmin2) = get_slot_xmins($node_standby_1, $slotname_2);
224241
note "new xmin $xmin2, old xmin $xmin";
225-
isnt($xmin2, $xmin, 'cascaded slot xmin with hs feedback has changed');
242+
isnt($xmin2, $xmin, 'xmin of cascaded slot with hs feedback has changed');
226243
is($catalog_xmin2, '',
227-
'cascaded slot xmin still null with hs_feedback unchanged');
244+
'catalog xmin of cascaded slot still null with hs_feedback unchanged');
228245

229246
note "disabling hot_standby_feedback";
230247

@@ -236,16 +253,22 @@ sub replay_check
236253
'ALTER SYSTEM SET hot_standby_feedback = off;');
237254
$node_standby_2->reload;
238255
replay_check();
239-
sleep(2);
256+
257+
wait_slot_xmins($node_master, $slotname_1,
258+
"xmin IS NULL AND catalog_xmin IS NULL");
240259

241260
($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1);
242-
is($xmin, '', 'non-cascaded slot xmin null with hs feedback reset');
261+
is($xmin, '', 'xmin of non-cascaded slot null with hs feedback reset');
243262
is($catalog_xmin, '',
244-
'non-cascaded slot xmin still null with hs_feedback reset');
263+
'catalog xmin of non-cascaded slot still null with hs_feedback reset');
264+
265+
wait_slot_xmins($node_standby_1, $slotname_2,
266+
"xmin IS NULL AND catalog_xmin IS NULL");
245267

246268
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
247-
is($xmin, '', 'cascaded slot xmin null with hs feedback reset');
248-
is($catalog_xmin, '', 'cascaded slot xmin still null with hs_feedback reset');
269+
is($xmin, '', 'xmin of cascaded slot null with hs feedback reset');
270+
is($catalog_xmin, '',
271+
'catalog xmin of cascaded slot still null with hs_feedback reset');
249272

250273
note "re-enabling hot_standby_feedback and disabling while stopped";
251274
$node_standby_2->safe_psql('postgres',
@@ -260,11 +283,13 @@ sub replay_check
260283
$node_standby_2->stop;
261284

262285
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
263-
isnt($xmin, '', 'cascaded slot xmin non-null with postgres shut down');
286+
isnt($xmin, '', 'xmin of cascaded slot non-null with postgres shut down');
264287

265288
# Xmin from a previous run should be cleared on startup.
266289
$node_standby_2->start;
267290

291+
wait_slot_xmins($node_standby_1, $slotname_2, "xmin IS NULL");
292+
268293
($xmin, $catalog_xmin) = get_slot_xmins($node_standby_1, $slotname_2);
269294
is($xmin, '',
270-
'cascaded slot xmin reset after startup with hs feedback reset');
295+
'xmin of cascaded slot reset after startup with hs feedback reset');

0 commit comments

Comments
 (0)