From bbd3363e128daec0e70952c1bb2f12ab1f6f1292 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 8 Jan 2018 17:32:09 -0500 Subject: Refactor subscription tests to use PostgresNode's wait_for_catchup This was nearly the same code. Extend wait_for_catchup to allow waiting for pg_current_wal_lsn() and use that in the subscription tests. Also change one use in the pg_rewind tests to use this. Also remove some broken code in wait_for_catchup and wait_for_slot_catchup. The error message in case the waiting failed wanted to show the current LSN, but the way it was written never worked. So since nobody ever cared, just remove it. Reviewed-by: Michael Paquier --- src/test/perl/PostgresNode.pm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/test/perl/PostgresNode.pm') diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index 80f68df246b..1d5ac4ee354 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -1465,7 +1465,8 @@ sub lsn =item $node->wait_for_catchup(standby_name, mode, target_lsn) -Wait for the node with application_name standby_name (usually from node->name) +Wait for the node with application_name standby_name (usually from node->name, +also works for logical subscriptions) until its replication location in pg_stat_replication equals or passes the upstream's WAL insert point at the time this function is called. By default the replay_lsn is waited for, but 'mode' may be specified to wait for any of @@ -1477,6 +1478,7 @@ poll_query_until timeout. Requires that the 'postgres' db exists and is accessible. target_lsn may be any arbitrary lsn, but is typically $master_node->lsn('insert'). +If omitted, pg_current_wal_lsn() is used. This is not a test. It die()s on failure. @@ -1497,7 +1499,15 @@ sub wait_for_catchup { $standby_name = $standby_name->name; } - die 'target_lsn must be specified' unless defined($target_lsn); + my $lsn_expr; + if (defined($target_lsn)) + { + $lsn_expr = "'$target_lsn'"; + } + else + { + $lsn_expr = 'pg_current_wal_lsn()' + } print "Waiting for replication conn " . $standby_name . "'s " . $mode @@ -1505,10 +1515,9 @@ sub wait_for_catchup . $target_lsn . " on " . $self->name . "\n"; my $query = -qq[SELECT '$target_lsn' <= ${mode}_lsn FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';]; +qq[SELECT $lsn_expr <= ${mode}_lsn FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';]; $self->poll_query_until('postgres', $query) - or die "timed out waiting for catchup, current location is " - . ($self->safe_psql('postgres', $query) || '(unknown)'); + or die "timed out waiting for catchup"; print "done\n"; } @@ -1550,8 +1559,7 @@ sub wait_for_slot_catchup my $query = qq[SELECT '$target_lsn' <= ${mode}_lsn FROM pg_catalog.pg_replication_slots WHERE slot_name = '$slot_name';]; $self->poll_query_until('postgres', $query) - or die "timed out waiting for catchup, current location is " - . ($self->safe_psql('postgres', $query) || '(unknown)'); + or die "timed out waiting for catchup"; print "done\n"; } -- cgit v1.2.3