1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

Back-Patch "Add wait_for_subscription_sync for TAP tests."

This was originally done in commit 0c20dd33db for 16 only, to eliminate
duplicate code and as an infrastructure that makes it easier to write
future tests. However, it has been suggested that it would be good to
back-patch this testing infrastructure to aid future tests in
back-branches.

Backpatch to all supported versions.

Author: Masahiko Sawada
Reviewed by: Amit Kapila, Shi yu
Discussion: https://postgr.es/m/CAD21AoC-fvAkaKHa4t1urupwL8xbAcWRePeETvshvy80f6WV1A@mail.gmail.com
Discussion: https://postgr.es/m/E1oJBIf-0006sw-SA@gemulon.postgresql.org
This commit is contained in:
Amit Kapila
2022-08-12 10:54:35 +05:30
parent 7944607831
commit 036642abc9
10 changed files with 65 additions and 67 deletions

View File

@ -2086,6 +2086,50 @@ sub wait_for_slot_catchup
=pod
=item $node->wait_for_subscription_sync(publisher, subname, dbname)
Wait for all tables in pg_subscription_rel to complete the initial
synchronization (i.e to be either in 'syncdone' or 'ready' state).
If the publisher node is given, additionally, check if the subscriber has
caught up to what has been committed on the primary. This is useful to
ensure that the initial data synchronization has been completed after
creating a new subscription.
If there is no active replication connection from this peer, wait until
poll_query_until timeout.
This is not a test. It die()s on failure.
=cut
sub wait_for_subscription_sync
{
my ($self, $publisher, $subname, $dbname) = @_;
my $name = $self->name;
$dbname = defined($dbname) ? $dbname : 'postgres';
# Wait for all tables to finish initial sync.
print "Waiting for all subscriptions in \"$name\" to synchronize data\n";
my $query =
qq[SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');];
$self->poll_query_until($dbname, $query)
or croak "timed out waiting for subscriber to synchronize data";
# Then, wait for the replication to catchup if required.
if (defined($publisher))
{
croak 'subscription name must be specified' unless defined($subname);
$publisher->wait_for_catchup($subname);
}
print "done\n";
return;
}
=pod
=item $node->wait_for_log(regexp, offset)
Waits for the contents of the server log file, starting at the given offset, to