From 681b1f0437e2a7cfa75137da9e75174bcc059858 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 | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/bin/pg_rewind/RewindTest.pm b/src/bin/pg_rewind/RewindTest.pm
index ae07b1b..39be3db 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";
@@ -179,7 +178,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";
 
 	remove_tree $log_path;
 }
@@ -225,7 +223,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
@@ -240,7 +239,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
@@ -252,7 +252,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.
@@ -270,8 +271,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";
 
@@ -289,7 +290,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.
@@ -305,12 +307,10 @@ sub run_pg_rewind
 	# Now run pg_rewind
 	if ($test_mode eq "local")
 	{
-
 		# 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",
@@ -359,7 +359,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.4.1

