mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Add wait_for_subscription_sync for TAP tests.
The TAP tests for logical replication in src/test/subscription are using
the following code in many places to make sure that the subscription is
synchronized with the publisher:
$node_publisher->wait_for_catchup('tap_sub');
$node_subscriber->poll_query_until('postgres',
qq[SELECT count(1) = 0
FROM pg_subscription_rel
WHERE srsubstate NOT IN ('r', 's')]);
The new function wait_for_subscription_sync() can be used to replace the
above code. This eliminates duplicated code and makes it easier to write
future tests.
Author: Masahiko Sawada
Reviewed by: Amit Kapila, Shi yu
Discussion: https://postgr.es/m/CAD21AoC-fvAkaKHa4t1urupwL8xbAcWRePeETvshvy80f6WV1A@mail.gmail.com
This commit is contained in:
@@ -2648,6 +2648,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
|
||||
|
||||
Reference in New Issue
Block a user