Skip to content

Commit df6ab94

Browse files
author
Amit Kapila
committed
Fix the random test failure in 001_rep_changes.
The check to test whether the subscription workers were restarting after a change in the subscription was failing. The reason was that the test was assuming the walsender started before it reaches the 'streaming' state and the walsender was exiting due to an error before that. Now, the walsender was erroring out before reaching the 'streaming' state because it tries to acquire the slot before the previous walsender has exited. In passing, improve the die messages so that it is easier to investigate the failures in the future if any. Reported-by: Michael Paquier, as per buildfarm Author: Ajin Cherian Reviewed-by: Masahiko Sawada, Amit Kapila Backpatch-through: 10, where this test was introduced Discussion: https://postgr.es/m/YRnhFxa9bo73wfpV@paquier.xyz
1 parent 6b96673 commit df6ab94

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/test/subscription/t/001_rep_changes.pl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,30 @@
255255
'update works with dropped subscriber column');
256256

257257
# check that change of connection string and/or publication list causes
258-
# restart of subscription workers. Not all of these are registered as tests
259-
# as we need to poll for a change but the test suite will fail none the less
260-
# when something goes wrong.
258+
# restart of subscription workers. We check the state along with
259+
# application_name to ensure that the walsender is (re)started.
260+
#
261+
# Not all of these are registered as tests as we need to poll for a change
262+
# but the test suite will fail none the less when something goes wrong.
261263
my $oldpid = $node_publisher->safe_psql('postgres',
262-
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
264+
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
263265
);
264266
$node_subscriber->safe_psql('postgres',
265267
"ALTER SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr sslmode=disable'"
266268
);
267269
$node_publisher->poll_query_until('postgres',
268-
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
269-
) or die "Timed out while waiting for apply to restart";
270+
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
271+
) or die "Timed out while waiting for apply to restart after changing CONNECTION";
270272

271273
$oldpid = $node_publisher->safe_psql('postgres',
272-
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
274+
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
273275
);
274276
$node_subscriber->safe_psql('postgres',
275277
"ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_ins_only WITH (copy_data = false)"
276278
);
277279
$node_publisher->poll_query_until('postgres',
278-
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
279-
) or die "Timed out while waiting for apply to restart";
280+
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
281+
) or die "Timed out while waiting for apply to restart after changing PUBLICATION";
280282

281283
$node_publisher->safe_psql('postgres',
282284
"INSERT INTO tab_ins SELECT generate_series(1001,1100)");
@@ -324,13 +326,13 @@
324326

325327
# check restart on rename
326328
$oldpid = $node_publisher->safe_psql('postgres',
327-
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
329+
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
328330
);
329331
$node_subscriber->safe_psql('postgres',
330332
"ALTER SUBSCRIPTION tap_sub RENAME TO tap_sub_renamed");
331333
$node_publisher->poll_query_until('postgres',
332-
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub_renamed';"
333-
) or die "Timed out while waiting for apply to restart";
334+
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub_renamed' AND state = 'streaming';"
335+
) or die "Timed out while waiting for apply to restart after renaming SUBSCRIPTION";
334336

335337
# check all the cleanup
336338
$node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION tap_sub_renamed");

0 commit comments

Comments
 (0)