From ad498861ef5355ac78b9bbd35d37f5a04698213d Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Sun, 19 Apr 2015 21:47:43 +0900
Subject: [PATCH 2/2] Prefer IPC's run to system_or_bail in pg_rewind tests

This facilitates log capture on Windows, the former method making tests
failing on Windows when multiple processes try to access this log file.
---
 src/bin/pg_rewind/RewindTest.pm | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_rewind/RewindTest.pm b/src/bin/pg_rewind/RewindTest.pm
index 088a021..93994ef 100644
--- a/src/bin/pg_rewind/RewindTest.pm
+++ b/src/bin/pg_rewind/RewindTest.pm
@@ -81,7 +81,6 @@ my $port_master=$ENV{PGPORT};
 my $port_standby=$port_master + 1;
 
 my $log_path;
-my $log_redirect;
 my $tempdir_short;
 
 my $connstr_master="port=$port_master";
@@ -173,7 +172,6 @@ sub init_rewind_test
 	my $test_mode = shift;
 
 	$log_path = "regress_log/pg_rewind_log_${testname}_${test_mode}";
-	$log_redirect = ($Config{osname} eq "MSWin32") ? "> nul" : ">>$log_path 2>&1";
 
 	$testroot = TestLib::tempdir;
 	$test_master_datadir="$testroot/data_master";
@@ -222,7 +220,8 @@ local replication all trust
 		"--listen-addresses=127.0.0.1 -p $port_master" :
 		"-k $tempdir_short --listen-addresses='' -p $port_master";
 
-	system_or_bail("pg_ctl -w -D $test_master_datadir -o \"$ctl_options\" start $log_redirect");
+	run(['pg_ctl', '-w', '-D', "$test_master_datadir", '-o',
+		 "$ctl_options", 'start'], '>>', $log_path, '2>&1');
 
 	#### Now run the test-specific parts to initialize the master before setting
 	# up standby
@@ -236,7 +235,8 @@ sub create_standby
 	remove_tree $test_standby_datadir;
 
 	# Base backup is taken with xlog files included
-	system_or_bail("pg_basebackup -D $test_standby_datadir -p $port_master -x $log_redirect");
+	run(['pg_basebackup', '-D', "$test_standby_datadir",
+		 '-p', "$port_master", '-x'], '>>', $log_path, '2>&1');
 	append_to_file("$test_standby_datadir/recovery.conf", qq(
 primary_conninfo='$connstr_master application_name=rewind_standby'
 standby_mode=on
@@ -248,7 +248,8 @@ recovery_target_timeline='latest'
 		"-k $tempdir_short --listen-addresses='' -p $port_standby";
 
 	# Start standby
-	system_or_bail("pg_ctl -w -D $test_standby_datadir -o \"$ctl_options\" start $log_redirect");
+	run(['pg_ctl', '-w', '-D', "$test_standby_datadir", '-o',
+		 "$ctl_options", 'start'], '>>', $log_path, '2>&1');
 
 	# Wait until the standby has caught up with the primary, by polling
 	# pg_stat_replication.
@@ -265,7 +266,8 @@ 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 $test_standby_datadir promote >>$log_path 2>&1");
+	run(['pg_ctl', '-w', '-D', "$test_standby_datadir", 'promote'],
+		'>>', $log_path, '2>&1');
 	poll_query_until("SELECT NOT pg_is_in_recovery()", $connstr_standby)
 		or die "Timed out while waiting for promotion of standby";
 }
@@ -275,7 +277,8 @@ sub run_pg_rewind
 	my $test_mode = shift;
 
 	# Stop the master and be ready to perform the rewind
-	system_or_bail("pg_ctl -w -D $test_master_datadir -m fast stop $log_redirect");
+	run(['pg_ctl', '-w', '-D', "$test_master_datadir", '-m',
+		 'fast', 'stop'], '>>', $log_path, '2>&1');
 
 	# At this point, the rewind processing is ready to run.
 	# We now have a very simple scenario with a few diverged WAL record.
@@ -290,7 +293,8 @@ sub run_pg_rewind
 	{
 		# Do rewind using a local pgdata as source
 		# Stop the master and be ready to perform the rewind
-		system_or_bail("pg_ctl -w -D $test_standby_datadir -m fast stop $log_redirect");
+		run(['pg_ctl', '-w', '-D', "$test_standby_datadir", '-m',
+			 'fast', 'stop'], '>>', $log_path, '2>&1');
 		my $result =
 			run(['pg_rewind',
 				 "--debug",
@@ -329,7 +333,8 @@ recovery_target_timeline='latest'
 		"-k $tempdir_short --listen-addresses='' -p $port_master";
 
 	# Restart the master to check that rewind went correctly
-	system_or_bail("pg_ctl -w -D $test_master_datadir -o \"$ctl_options\" start $log_redirect");
+	run(['pg_ctl', '-w', '-D', "$test_master_datadir", '-o',
+		 "$ctl_options", 'start'], '>>', $log_path, '2>&1');
 
 	#### Now run the test-specific parts to check the result
 }
-- 
2.3.6

