kuroda.diffs

application/octet-stream

Filename: kuroda.diffs
Type: application/octet-stream
Part: 0
Message: RE: Enhance 'pg_createsubscriber' to retrieve databases automatically when no database is provided.
diff --git a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
index 85b36487045..e1f9c2f9543 100644
--- a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
+++ b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
@@ -41,6 +41,25 @@ sub generate_db
 	return $dbname;
 }
 
+# Wait for subscriptions on the subscriber to catch up all changes.
+sub wait_for_all_subscriptions_caught_up
+{
+	my ($node_p, $node_s) = @_;
+
+	# Get subscription names
+	my $result = $node_s->safe_psql(
+		'postgres', qq(
+		SELECT subname FROM pg_subscription WHERE subname ~ '^pg_createsubscriber_'
+	));
+	my @subnames = split("\n", $result);
+
+	# Wait for all subscriptions to catch up
+	foreach my $subname (@subnames)
+	{
+		$node_p->wait_for_catchup($subname);
+	}
+}
+
 #
 # Test mandatory options
 command_fails(['pg_createsubscriber'],
@@ -553,16 +572,7 @@ $result = $node_s->safe_psql(
 ));
 is($result, qq(0), 'pre-existing subscription was dropped');
 
-# Get subscription names
-$result = $node_s->safe_psql(
-	'postgres', qq(
-	SELECT subname FROM pg_subscription WHERE subname ~ '^pg_createsubscriber_'
-));
-my @subnames = split("\n", $result);
-
-# Wait subscriber to catch up
-$node_s->wait_for_subscription_sync($node_p, $subnames[0]);
-$node_s->wait_for_subscription_sync($node_p, $subnames[1]);
+wait_for_all_subscriptions_caught_up($node_p, $node_s);
 
 # Confirm the failover slot has been removed
 $result = $node_s->safe_psql($db1,
@@ -601,10 +611,6 @@ $node_p->safe_psql('postgres', 'CREATE TABLE tbl1 (a text)');
 $node_p->backup('backup_3');
 my $node_u = PostgreSQL::Test::Cluster->new('node_u');
 $node_u->init_from_backup($node_p, 'backup_3', has_streaming => 1);
-$node_u->append_conf(
-	'postgresql.conf', qq[
-primary_conninfo = '$pconnstr dbname=postgres'
-]);
 $node_u->set_standby_mode();
 
 # run pg_createsubscriber with '--all' option without '--dry-run'
@@ -645,16 +651,7 @@ is($result, '0', 'subscription is not created on template databases');
 $node_p->safe_psql('postgres', "INSERT INTO tbl1 VALUES('first row')");
 $node_p->safe_psql($db1, "INSERT INTO tbl1 VALUES('fourth row')");
 
-# Get subscription names
-$result = $node_u->safe_psql(
-	'postgres', qq(
-	SELECT subname FROM pg_subscription WHERE subname ~ '^pg_createsubscriber_'
-));
-my @subnames1 = split("\n", $result);
-
-# Wait subscriber to catch up
-$node_u->wait_for_subscription_sync($node_p, $subnames1[0]);
-$node_u->wait_for_subscription_sync($node_p, $subnames1[1]);
+wait_for_all_subscriptions_caught_up($node_p, $node_u);
 
 # Check result in database 'postgres' of node U
 $result = $node_u->safe_psql('postgres', 'SELECT * FROM tbl1');