Skip to content

Commit b7ad093

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 0d892cf commit b7ad093

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
@@ -414,28 +414,30 @@
414414
'update works with dropped subscriber column');
415415

416416
# check that change of connection string and/or publication list causes
417-
# restart of subscription workers. Not all of these are registered as tests
418-
# as we need to poll for a change but the test suite will fail none the less
419-
# when something goes wrong.
417+
# restart of subscription workers. We check the state along with
418+
# application_name to ensure that the walsender is (re)started.
419+
#
420+
# Not all of these are registered as tests as we need to poll for a change
421+
# but the test suite will fail none the less when something goes wrong.
420422
my $oldpid = $node_publisher->safe_psql('postgres',
421-
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
423+
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
422424
);
423425
$node_subscriber->safe_psql('postgres',
424426
"ALTER SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr sslmode=disable'"
425427
);
426428
$node_publisher->poll_query_until('postgres',
427-
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
428-
) or die "Timed out while waiting for apply to restart";
429+
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
430+
) or die "Timed out while waiting for apply to restart after changing CONNECTION";
429431

430432
$oldpid = $node_publisher->safe_psql('postgres',
431-
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
433+
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
432434
);
433435
$node_subscriber->safe_psql('postgres',
434436
"ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_ins_only WITH (copy_data = false)"
435437
);
436438
$node_publisher->poll_query_until('postgres',
437-
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
438-
) or die "Timed out while waiting for apply to restart";
439+
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
440+
) or die "Timed out while waiting for apply to restart after changing PUBLICATION";
439441

440442
$node_publisher->safe_psql('postgres',
441443
"INSERT INTO tab_ins SELECT generate_series(1001,1100)");
@@ -483,13 +485,13 @@
483485

484486
# check restart on rename
485487
$oldpid = $node_publisher->safe_psql('postgres',
486-
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
488+
"SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub' AND state = 'streaming';"
487489
);
488490
$node_subscriber->safe_psql('postgres',
489491
"ALTER SUBSCRIPTION tap_sub RENAME TO tap_sub_renamed");
490492
$node_publisher->poll_query_until('postgres',
491-
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub_renamed';"
492-
) or die "Timed out while waiting for apply to restart";
493+
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub_renamed' AND state = 'streaming';"
494+
) or die "Timed out while waiting for apply to restart after renaming SUBSCRIPTION";
493495

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

0 commit comments

Comments
 (0)