From f866f5a211ba1fc3c34b4272c9b752ced90684ae Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Wed, 17 Feb 2016 15:21:32 +0900
Subject: [PATCH 2/3] Add routine for node promotion in PostgresNode

This is useful for tests to trigger a promotion on a node via pg_ctl,
and pg_rewind can make immediate use of it.
---
 src/bin/pg_rewind/RewindTest.pm |  2 +-
 src/test/perl/PostgresNode.pm   | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_rewind/RewindTest.pm b/src/bin/pg_rewind/RewindTest.pm
index 68834cd..e204830 100644
--- a/src/bin/pg_rewind/RewindTest.pm
+++ b/src/bin/pg_rewind/RewindTest.pm
@@ -177,7 +177,7 @@ sub promote_standby
 	# Now promote slave and insert some new data on master, this will put
 	# the master out-of-sync with the standby. Wait until the standby is
 	# out of recovery mode, and is ready to accept read-write connections.
-	system_or_bail('pg_ctl', '-w', '-D', $node_standby->data_dir, 'promote');
+	$node_standby->promote;
 	$node_standby->poll_query_until('postgres',
 		"SELECT NOT pg_is_in_recovery()")
 	  or die "Timed out while waiting for promotion of standby";
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm
index 2ab9aee..5a57e31 100644
--- a/src/test/perl/PostgresNode.pm
+++ b/src/test/perl/PostgresNode.pm
@@ -294,6 +294,18 @@ sub restart
 	$self->_update_pid;
 }
 
+sub promote
+{
+	my ($self)  = @_;
+	my $port    = $self->port;
+	my $pgdata  = $self->data_dir;
+	my $logfile = $self->logfile;
+	my $name    = $self->name;
+	print "### Promoting node \"$name\"\n";
+	TestLib::system_log('pg_ctl', '-D', $pgdata, '-w', '-l', $logfile,
+						'promote');
+}
+
 sub _update_pid
 {
 	my $self = shift;
-- 
2.7.1

