From d30daa883ab27a0acda7c12235608cdaa77e4c77 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 87f407a..f86f64e 100644
--- a/src/bin/pg_rewind/RewindTest.pm
+++ b/src/bin/pg_rewind/RewindTest.pm
@@ -77,7 +77,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";
@@ -138,7 +137,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";
@@ -187,7 +185,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
@@ -201,7 +200,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
@@ -213,7 +213,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 comparing
 	# WAL positions on both nodes. Note that this is fine
@@ -248,7 +249,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. Be sure that we leave here
 	# with a standby actually ready for the next operations.
-	system_or_bail("pg_ctl -w -D $test_standby_datadir promote $log_redirect");
+	run(['pg_ctl', '-w', '-D', "$test_standby_datadir", 'promote'],
+		'>>', $log_path, '2>&1');
 	my $max_attempts = 30;
 	my $attempts = 0;
 	while ($attempts < $max_attempts)
@@ -278,7 +280,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.
@@ -293,7 +296,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",
@@ -332,7 +336,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.5

