On Fri, Apr 10, 2015 at 11:29 AM, Michael Paquier wrote: > Here is a v2 with the following changes: > - Use an environment variable to define where pg_regress is located. > - Use SSPI to access a node in the tests, to secure the test environment. > - Rebase on latest HEAD > - SSL tests are run only if build is configured with openssl > > A couple of things to note: > - pg_rewind tests are still disabled, waiting for the outcome of > 5519f169.8030...@gmx.net. They will need some tweaks. > - SSL tests can work if an equivalent of cp is available, like > something installed with msysgit... IMO the scripts in src/test/ssl > should be patched to be made more portable (see > http://www.postgresql.org/message-id/CAB7nPqQivFxnSjPwkyapa8=HTGm0hfDNvdGcM3=hkk6fpt0...@mail.gmail.com) > - I tested the scripts with MinGW and this patch and got them working. > As prove can fail because of a bad perl interpreter, pointing to > /usr/bin/perl, it is necessary to enforce "PROVE = c:\Perl64\bin\perl > c:\Perl64\bin\prove" or similar. That's not beautiful, but it works, > and the t/ scripts need no further modifications. At least I checked > that.
And here is v3 with support for pg_rewind tests. One thing that I noticed with this stuff is that the log redirection fails on Windows with "cannot access file because it is used by another process", because of system_or_bail that is used by a set of pg_ctl commands in RewindTest.pm to stop, start and promote the test servers. I am attaching a second patch switching those calls from system_or_bail to IPC's run(), making the log capture method completely consistent across platforms. In the first patch log redirection is done to NUL to make the test work even if log output is lost, the split is done for clarity and those patches should be applied together. Note as well that this patch uses the following patches fixing independent issues: - Replace use of rm in initdb tests by rmtree: http://www.postgresql.org/message-id/cab7npqqqzjshxncpyco5vr2dmelt8dqedetqrzmj7tmnqb5...@mail.gmail.com - Add --debug for pg_rewind remote mode: http://www.postgresql.org/message-id/CAB7nPqSMRFZcfB-b6Un8KvnJKWNLi+qckkXgsy1Fu4dQBif=g...@mail.gmail.com - Improve sleep processing of pg_rewind, windows being sometimes susceptible about that as well... http://www.postgresql.org/message-id/cab7npqsqftfge-whbprd99bebjox3z+pepwa+tubxa0fdtu...@mail.gmail.com Regards, -- Michael
From 88cbadb55a89593f56fb40a6b496771dbc7b2cf9 Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@otacoo.com> Date: Sun, 19 Apr 2015 21:46:02 +0900 Subject: [PATCH 1/2] Add support for TAP tests on Windows Nodes initialized by the TAP tests use SSPI to securely perform the tests, and test scripts are patched in a couple of places to support Windows grammar. In the case of MSVC, tests can be run with this command: vcregress tapcheck --- .gitignore | 3 + doc/src/sgml/install-windows.sgml | 1 + src/Makefile.global.in | 2 +- src/bin/initdb/t/001_initdb.pl | 18 ++-- src/bin/pg_basebackup/t/010_pg_basebackup.pl | 79 +++++++++------- src/bin/pg_controldata/t/001_pg_controldata.pl | 5 +- src/bin/pg_ctl/t/001_start_stop.pl | 14 ++- src/bin/pg_ctl/t/002_status.pl | 12 ++- src/bin/pg_rewind/RewindTest.pm | 119 ++++++++++++++++++++----- src/bin/scripts/t/020_createdb.pl | 3 + src/test/perl/TestLib.pm | 25 ++++-- src/tools/msvc/vcregress.pl | 54 ++++++++++- 12 files changed, 263 insertions(+), 72 deletions(-) diff --git a/.gitignore b/.gitignore index 8d3af50..3cd37fe 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ lib*.pc /pgsql.sln.cache /Debug/ /Release/ + +# Generated by tests +/tmp_check/ diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml index d154b44..2047790 100644 --- a/doc/src/sgml/install-windows.sgml +++ b/doc/src/sgml/install-windows.sgml @@ -439,6 +439,7 @@ $ENV{CONFIG}="Debug"; <userinput>vcregress modulescheck</userinput> <userinput>vcregress ecpgcheck</userinput> <userinput>vcregress isolationcheck</userinput> +<userinput>vcregress tapcheck</userinput> <userinput>vcregress upgradecheck</userinput> </screen> diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 4b06fc2..b27ed78 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -324,7 +324,7 @@ endef define prove_check $(MKDIR_P) tmp_check/log $(MAKE) -C $(top_builddir) DESTDIR='$(CURDIR)'/tmp_check/install install >'$(CURDIR)'/tmp_check/log/install.log 2>&1 -cd $(srcdir) && TESTDIR='$(CURDIR)' PATH="$(CURDIR)/tmp_check/install$(bindir):$$PATH" $(call add_to_path,$(ld_library_path_var),$(CURDIR)/tmp_check/install$(libdir)) top_builddir='$(CURDIR)/$(top_builddir)' PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl +cd $(srcdir) && TESTDIR='$(CURDIR)' TESTREGRESS='$(top_builddir)/src/test/regress/pg_regress' PATH="$(CURDIR)/tmp_check/install$(bindir):$$PATH" $(call add_to_path,$(ld_library_path_var),$(CURDIR)/tmp_check/install$(libdir)) top_builddir='$(CURDIR)/$(top_builddir)' PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl endef else diff --git a/src/bin/initdb/t/001_initdb.pl b/src/bin/initdb/t/001_initdb.pl index d12be84..0865107 100644 --- a/src/bin/initdb/t/001_initdb.pl +++ b/src/bin/initdb/t/001_initdb.pl @@ -1,6 +1,8 @@ use strict; use warnings; +use Config; use TestLib; +use File::Path qw(rmtree); use Test::More tests => 19; my $tempdir = TestLib::tempdir; @@ -18,27 +20,31 @@ command_fails([ 'initdb', '-S', "$tempdir/data3" ], mkdir "$tempdir/data4" or BAIL_OUT($!); command_ok([ 'initdb', "$tempdir/data4" ], 'existing empty data directory'); -system_or_bail "rm -rf '$tempdir'/*"; - +rmtree($tempdir); +mkdir $tempdir; command_ok([ 'initdb', '-X', "$tempdir/pgxlog", "$tempdir/data" ], 'separate xlog directory'); -system_or_bail "rm -rf '$tempdir'/*"; +rmtree($tempdir); +mkdir $tempdir; command_fails( [ 'initdb', "$tempdir/data", '-X', 'pgxlog' ], 'relative xlog directory not allowed'); -system_or_bail "rm -rf '$tempdir'/*"; +rmtree($tempdir); +mkdir $tempdir; mkdir "$tempdir/pgxlog"; command_ok([ 'initdb', '-X', "$tempdir/pgxlog", "$tempdir/data" ], 'existing empty xlog directory'); -system_or_bail "rm -rf '$tempdir'/*"; +rmtree($tempdir); +mkdir $tempdir; mkdir "$tempdir/pgxlog"; mkdir "$tempdir/pgxlog/lost+found"; command_fails([ 'initdb', '-X', "$tempdir/pgxlog", "$tempdir/data" ], 'existing nonempty xlog directory'); -system_or_bail "rm -rf '$tempdir'/*"; +rmtree($tempdir); +mkdir $tempdir; command_ok([ 'initdb', '-T', 'german', "$tempdir/data" ], 'select default dictionary'); diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index 7e9a776..4cb1b5a 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -1,8 +1,9 @@ use strict; use warnings; use Cwd; +use Config; use TestLib; -use Test::More tests => 35; +use Test::More tests => ($Config{osname} eq "MSWin32") ? 26 : 35; program_help_ok('pg_basebackup'); program_version_ok('pg_basebackup'); @@ -17,10 +18,20 @@ command_fails( [ 'pg_basebackup', '-D', "$tempdir/backup" ], 'pg_basebackup fails because of hba'); +# Use SSPI on Windows, node has been initialized already accordingly +# by pg_regress --config-auth. open HBA, ">>$tempdir/pgdata/pg_hba.conf"; -print HBA "local replication all trust\n"; -print HBA "host replication all 127.0.0.1/32 trust\n"; -print HBA "host replication all ::1/128 trust\n"; +if ($Config{osname} ne "MSWin32") +{ + print HBA "local replication all trust\n"; + print HBA "host replication all 127.0.0.1/32 trust\n"; + print HBA "host replication all ::1/128 trust\n"; +} +else +{ + print HBA "host replication all 127.0.0.1/32 sspi include_realm=1 map=regress\n"; + print HBA "host replication all ::1/128 sspi include_realm=1 map=regress\n"; +} close HBA; system_or_bail 'pg_ctl', '-s', '-D', "$tempdir/pgdata", 'reload'; @@ -56,6 +67,39 @@ command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l1", '-Ft' ], 'pg_basebackup tar with long name fails'); unlink "$tempdir/pgdata/$superlongname"; +command_fails( + [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T=/foo" ], + '-T with empty old directory fails'); +command_fails( + [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T/foo=" ], + '-T with empty new directory fails'); +command_fails( + [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', + "-T/foo=/bar=/baz" ], + '-T with multiple = fails'); +command_fails( + [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo=/bar" ], + '-T with old directory not absolute fails'); +command_fails( + [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T/foo=bar" ], + '-T with new directory not absolute fails'); +command_fails( + [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo" ], + '-T with invalid format fails'); + +mkdir "$tempdir/$superlongname"; +psql 'postgres', "CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';"; +command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ], + 'pg_basebackup tar with long symlink target fails'); +psql 'postgres', "DROP TABLESPACE tblspc3;"; + +# Windows does not support symlink, which is what the rest of the tests +# need, so simply leave. +if ($Config{osname} eq "MSWin32") +{ + exit 0; +} + # Create a temporary directory in the system location and symlink it # to our physical temp location. That way we can use shorter names # for the tablespace directories, which hopefully won't run afoul of @@ -102,31 +146,4 @@ command_ok( "-T$shorter_tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2" ], 'mapping tablespace with = sign in path'); ok(-d "$tempdir/tbackup/tbl=spc2", 'tablespace with = sign was relocated'); - psql 'postgres', "DROP TABLESPACE tblspc2;"; - -command_fails( - [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T=/foo" ], - '-T with empty old directory fails'); -command_fails( - [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T/foo=" ], - '-T with empty new directory fails'); -command_fails( - [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', - "-T/foo=/bar=/baz" ], - '-T with multiple = fails'); -command_fails( - [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo=/bar" ], - '-T with old directory not absolute fails'); -command_fails( - [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T/foo=bar" ], - '-T with new directory not absolute fails'); -command_fails( - [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo" ], - '-T with invalid format fails'); - -mkdir "$tempdir/$superlongname"; -psql 'postgres', "CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';"; -command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ], - 'pg_basebackup tar with long symlink target fails'); -psql 'postgres', "DROP TABLESPACE tblspc3;"; diff --git a/src/bin/pg_controldata/t/001_pg_controldata.pl b/src/bin/pg_controldata/t/001_pg_controldata.pl index a4180e7..fc18a3a 100644 --- a/src/bin/pg_controldata/t/001_pg_controldata.pl +++ b/src/bin/pg_controldata/t/001_pg_controldata.pl @@ -1,5 +1,6 @@ use strict; use warnings; +use Config; use TestLib; use Test::More tests => 13; @@ -11,6 +12,8 @@ program_options_handling_ok('pg_controldata'); command_fails(['pg_controldata'], 'pg_controldata without arguments fails'); command_fails([ 'pg_controldata', 'nonexistent' ], 'pg_controldata with nonexistent directory fails'); -system_or_bail "initdb -D '$tempdir'/data -A trust >/dev/null"; + +my $null_ptr = ($Config{osname} eq "MSWin32") ? "NUL" : "/dev/null"; +system_or_bail "initdb -D $tempdir/data -A trust > $null_ptr"; command_like([ 'pg_controldata', "$tempdir/data" ], qr/checkpoint/, 'pg_controldata produces output'); diff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.pl index 17309e8..66f67f3 100644 --- a/src/bin/pg_ctl/t/001_start_stop.pl +++ b/src/bin/pg_ctl/t/001_start_stop.pl @@ -1,5 +1,6 @@ use strict; use warnings; +use Config; use TestLib; use Test::More tests => 17; @@ -15,12 +16,19 @@ command_exit_is([ 'pg_ctl', 'start', '-D', "$tempdir/nonexistent" ], command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data" ], 'pg_ctl initdb'); command_ok( - [ "$ENV{top_builddir}/src/test/regress/pg_regress", '--config-auth', + [ $ENV{TESTREGRESS}, '--config-auth', "$tempdir/data" ], 'configure authentication'); open CONF, ">>$tempdir/data/postgresql.conf"; -print CONF "listen_addresses = ''\n"; -print CONF "unix_socket_directories = '$tempdir_short'\n"; +if ($Config{osname} eq "MSWin32") +{ + print CONF "listen_addresses = '127.0.0.1'\n"; +} +else +{ + print CONF "listen_addresses = ''\n"; + print CONF "unix_socket_directories = '$tempdir_short'\n"; +} close CONF; command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ], 'pg_ctl start -w'); diff --git a/src/bin/pg_ctl/t/002_status.pl b/src/bin/pg_ctl/t/002_status.pl index b8cbbda..480a02e 100644 --- a/src/bin/pg_ctl/t/002_status.pl +++ b/src/bin/pg_ctl/t/002_status.pl @@ -1,5 +1,6 @@ use strict; use warnings; +use Config; use TestLib; use Test::More tests => 3; @@ -11,8 +12,15 @@ command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/nonexistent" ], standard_initdb "$tempdir/data"; open CONF, ">>$tempdir/data/postgresql.conf"; -print CONF "listen_addresses = ''\n"; -print CONF "unix_socket_directories = '$tempdir_short'\n"; +if ($Config{osname} eq "MSWin32") +{ + print CONF "listen_addresses = '127.0.0.1'\n"; +} +else +{ + print CONF "listen_addresses = ''\n"; + print CONF "unix_socket_directories = '$tempdir_short'\n"; +} close CONF; command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ], diff --git a/src/bin/pg_rewind/RewindTest.pm b/src/bin/pg_rewind/RewindTest.pm index e6a5b9b..87f407a 100644 --- a/src/bin/pg_rewind/RewindTest.pm +++ b/src/bin/pg_rewind/RewindTest.pm @@ -38,6 +38,7 @@ use warnings; use TestLib; use Test::More; +use Config; use File::Copy; use File::Path qw(remove_tree); use IPC::Run qw(run start); @@ -64,11 +65,9 @@ our @EXPORT = qw( # Adjust these paths for your environment -my $testroot = "./tmp_check"; -our $test_master_datadir="$testroot/data_master"; -our $test_standby_datadir="$testroot/data_standby"; - -mkdir $testroot; +my $testroot; +our $test_master_datadir; +our $test_standby_datadir; # Log files are created here mkdir "regress_log"; @@ -78,6 +77,7 @@ 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"; @@ -137,7 +137,12 @@ sub init_rewind_test my $testname = shift; my $test_mode = shift; - $log_path="regress_log/pg_rewind_log_${testname}_${test_mode}"; + $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"; + $test_standby_datadir="$testroot/data_standby"; remove_tree $log_path; } @@ -164,15 +169,30 @@ max_connections = 10 )); # Accept replication connections on master - append_to_file("$test_master_datadir/pg_hba.conf", qq( + if ($Config{osname} eq "MSWin32") + { + append_to_file("$test_master_datadir/pg_hba.conf", qq( +host replication all 127.0.0.1/32 sspi include_realm=1 map=regress +host replication all ::1/128 sspi include_realm=1 map=regress +)); + } + else + { + append_to_file("$test_master_datadir/pg_hba.conf", qq( local replication all trust )); + } + + my $ctl_options = ($Config{osname} eq "MSWin32") ? + "--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 \"-k $tempdir_short --listen-addresses='' -p $port_master\" start >>$log_path 2>&1"); + system_or_bail("pg_ctl -w -D $test_master_datadir -o \"$ctl_options\" start $log_redirect"); #### Now run the test-specific parts to initialize the master before setting # up standby - $ENV{PGHOST} = $tempdir_short; + $ENV{PGHOST} = ($Config{osname} eq "MSWin32") ? + "127.0.0.1" : $tempdir_short; } sub create_standby @@ -181,18 +201,43 @@ 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_path 2>&1"); + system_or_bail("pg_basebackup -D $test_standby_datadir -p $port_master -x $log_redirect"); append_to_file("$test_standby_datadir/recovery.conf", qq( -primary_conninfo='$connstr_master' +primary_conninfo='$connstr_master application_name=rewind_standby' standby_mode=on recovery_target_timeline='latest' )); + my $ctl_options = ($Config{osname} eq "MSWin32") ? + "--listen-addresses=127.0.0.1 -p $port_standby" : + "-k $tempdir_short --listen-addresses='' -p $port_standby"; + # Start standby - system_or_bail("pg_ctl -w -D $test_standby_datadir -o \"-k $tempdir_short --listen-addresses='' -p $port_standby\" start >>$log_path 2>&1"); + system_or_bail("pg_ctl -w -D $test_standby_datadir -o \"$ctl_options\" start $log_redirect"); - # sleep a bit to make sure the standby has caught up. - sleep 1; + # Wait until the standby has caught up with the primary by comparing + # WAL positions on both nodes. Note that this is fine + my $max_attempts = 30; + my $attempts = 0; + while ($attempts < $max_attempts) + { + # Wait a bit before proceeding. + sleep 1; + $attempts++; + + my $query = "SELECT pg_current_xlog_location() = replay_location FROM pg_stat_replication WHERE application_name = 'rewind_standby';"; + my $cmd = ['psql', '-At', '-c', "$query", '-d', "$connstr_master" ]; + my ($res, $stdout, $stderr) = command_result($cmd); + chomp($stdout); + if ($stdout eq "t") + { + last; + } + } + if ($attempts == $max_attempts) + { + die "Maximum number of attempts reached when waiting for standby to catch up"; + } } sub promote_standby @@ -201,9 +246,31 @@ sub promote_standby # up standby # Now promote slave and insert some new data on master, this will put - # the master out-of-sync with the standby. - system_or_bail("pg_ctl -w -D $test_standby_datadir promote >>$log_path 2>&1"); - sleep 2; + # 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"); + my $max_attempts = 30; + my $attempts = 0; + while ($attempts < $max_attempts) + { + # Wait a bit before proceeding, promotion may have not taken effect + # in such a short time. + sleep 1; + $attempts++; + + my $query = "SELECT pg_is_in_recovery()"; + my $cmd = ['psql', '-At', '-c', "$query", '-d', "$connstr_standby" ]; + my ($res, $stdout, $stderr) = command_result($cmd); + chomp($stdout); + if ($stdout eq "f") + { + last; + } + } + if ($attempts == $max_attempts) + { + die "Maximum number of attempts reached when waiting for promotion of standby"; + } } sub run_pg_rewind @@ -211,7 +278,7 @@ 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 stop -m fast >>$log_path 2>&1"); + system_or_bail("pg_ctl -w -D $test_master_datadir -m fast stop $log_redirect"); # At this point, the rewind processing is ready to run. # We now have a very simple scenario with a few diverged WAL record. @@ -226,7 +293,7 @@ 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 stop -m fast >>$log_path 2>&1"); + system_or_bail("pg_ctl -w -D $test_standby_datadir -m fast stop $log_redirect"); my $result = run(['pg_rewind', "--debug", @@ -240,6 +307,7 @@ sub run_pg_rewind # Do rewind using a remote connection as source my $result = run(['pg_rewind', + "--debug", "--source-server", "port=$port_standby dbname=postgres", "--target-pgdata=$test_master_datadir"], '>>', $log_path, '2>&1'); @@ -259,8 +327,12 @@ standby_mode=on recovery_target_timeline='latest' )); + my $ctl_options = ($Config{osname} eq "MSWin32") ? + "--listen-addresses=127.0.0.1 -p $port_master" : + "-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 \"-k $tempdir_short --listen-addresses='' -p $port_master\" start >>$log_path 2>&1"); + system_or_bail("pg_ctl -w -D $test_master_datadir -o \"$ctl_options\" start $log_redirect"); #### Now run the test-specific parts to check the result } @@ -268,13 +340,16 @@ recovery_target_timeline='latest' # Clean up after the test. Stop both servers, if they're still running. sub clean_rewind_test { + my $null_redirect = ($Config{osname} eq "MSWin32") ? + "2> nul" : "2> /dev/null"; + if ($test_master_datadir) { - system "pg_ctl -D $test_master_datadir -s -m immediate stop 2> /dev/null"; + system "pg_ctl -D $test_master_datadir -w -s -m immediate stop $null_redirect"; } if ($test_standby_datadir) { - system "pg_ctl -D $test_standby_datadir -s -m immediate stop 2> /dev/null"; + system "pg_ctl -D $test_standby_datadir -w -s -m immediate stop $null_redirect"; } } diff --git a/src/bin/scripts/t/020_createdb.pl b/src/bin/scripts/t/020_createdb.pl index a44283c..7e769e4 100644 --- a/src/bin/scripts/t/020_createdb.pl +++ b/src/bin/scripts/t/020_createdb.pl @@ -1,5 +1,6 @@ use strict; use warnings; +use Config; use TestLib; use Test::More tests => 13; @@ -14,6 +15,8 @@ issues_sql_like( [ 'createdb', 'foobar1' ], qr/statement: CREATE DATABASE foobar1/, 'SQL CREATE DATABASE run'); + +my $encoding = ($Config{osname} eq "MSWin32") ? "win1252" : "LATIN1" ; issues_sql_like( [ 'createdb', '-l', 'C', '-E', 'LATIN1', '-T', 'template0', 'foobar2' ], qr/statement: CREATE DATABASE foobar2 ENCODING 'LATIN1'/, diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 003cd9a..8714024 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -3,6 +3,7 @@ package TestLib; use strict; use warnings; +use Config; use Exporter 'import'; our @EXPORT = qw( tempdir @@ -16,6 +17,7 @@ our @EXPORT = qw( command_ok command_fails command_exit_is + command_result program_help_ok program_version_ok program_options_handling_ok @@ -73,8 +75,9 @@ sub tempdir_short sub standard_initdb { my $pgdata = shift; - system_or_bail("initdb -D '$pgdata' -A trust -N >/dev/null"); - system_or_bail("$ENV{top_builddir}/src/test/regress/pg_regress", + my $null_ptr = ($Config{osname} eq "MSWin32") ? "NUL" : "/dev/null"; + system_or_bail("initdb -D $pgdata -A trust -N > $null_ptr"); + system_or_bail($ENV{TESTREGRESS}, '--config-auth', $pgdata); } @@ -87,10 +90,12 @@ sub start_test_server my $tempdir_short = tempdir_short; + my $listen_addresses = ($Config{osname} eq "MSWin32") ? "127.0.0.1" : "''"; + standard_initdb "$tempdir/pgdata"; $ret = system 'pg_ctl', '-D', "$tempdir/pgdata", '-s', '-w', '-l', "$tempdir/logfile", '-o', - "--fsync=off -k $tempdir_short --listen-addresses='' --log-statement=all", + "--fsync=off -k $tempdir_short --listen-addresses=$listen_addresses --log-statement=all", 'start'; if ($ret != 0) @@ -99,7 +104,7 @@ sub start_test_server BAIL_OUT("pg_ctl failed"); } - $ENV{PGHOST} = $tempdir_short; + $ENV{PGHOST} = ($Config{osname} eq "MSWin32") ? "127.0.0.1" : $tempdir_short; $test_server_datadir = "$tempdir/pgdata"; $test_server_logfile = "$tempdir/logfile"; } @@ -158,7 +163,17 @@ sub command_exit_is my $h = start $cmd, '>', File::Spec->devnull(), '2>', File::Spec->devnull(); $h->finish(); - is($h->result(0), $expected, $test_name); + my $result = ($Config{osname} eq "MSWin32") ? + ($h->full_results)[0] : $h->result(0); + is($result, $expected, $test_name); +} + +sub command_result +{ + my ($cmd) = @_; + my ($stdout, $stderr); + my $result = run $cmd, '>', \$stdout, '2>', \$stderr; + return ($result, $stdout, $stderr); } sub program_help_ok diff --git a/src/tools/msvc/vcregress.pl b/src/tools/msvc/vcregress.pl index c3143ac..1cc5495 100644 --- a/src/tools/msvc/vcregress.pl +++ b/src/tools/msvc/vcregress.pl @@ -7,7 +7,9 @@ use strict; our $config; use Cwd; +use File::Basename; use File::Copy; +use File::Find (); use Install qw(Install); @@ -31,7 +33,7 @@ if (-e "src/tools/msvc/buildenv.pl") my $what = shift || ""; if ($what =~ -/^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck)$/i +/^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck|tapcheck)$/i ) { $what = uc $what; @@ -78,6 +80,7 @@ my %command = ( CONTRIBCHECK => \&contribcheck, MODULESCHECK => \&modulescheck, ISOLATIONCHECK => \&isolationcheck, + TAPCHECK => \&tapcheck, UPGRADECHECK => \&upgradecheck,); my $proc = $command{$what}; @@ -163,6 +166,55 @@ sub isolationcheck exit $status if $status; } +sub tapcheck +{ + # Temporary installation cannot be located deeper in src/ because + # of interferences with Install.pm scanning its content. So install + # it just once for all the tests. + my $tmp_root = "$topdir/tmp_check"; + (mkdir $tmp_root || die $!) unless -d $tmp_root; + my $tmp_install = "$tmp_root/install"; + Install($tmp_install, "all", $config); + my @args = ( + "prove", + "--verbose", + "t/*.pl"); + + # Set environment variables common to all the tests + my ($bindir, $libdir, $oldsrc, $newsrc) = + ("$tmp_install/bin", "$tmp_install/lib", $topdir, $topdir); + + $ENV{PATH} = "$bindir;$ENV{PATH}"; + $ENV{PERL5LIB} = "$topdir/src/test/perl;$ENV{PERL5LIB}"; + $ENV{TESTREGRESS} = "$topdir/$Config/pg_regress/pg_regress"; + + # Find out all the existing TAP tests by simply looking for t/ + # in the tree. + my $tap_dirs = []; + my @top_dir = ($topdir); + File::Find::find( + { wanted => sub { + /^t\z/s + && push(@$tap_dirs, $File::Find::name); + } + }, + @top_dir); + + # Process each test + foreach my $test_path (@$tap_dirs) + { + next if ($test_path =~ /\/ssl\// && !defined($config->{openssl})); + + my $dir = dirname($test_path); + chdir $dir; + # Reset those values, they may have been changed by another test. + $ENV{TESTDIR} = "$dir"; + system(@args); + my $status = $? >> 8; + exit $status if $status; + } +} + sub plcheck { chdir "../../pl"; -- 2.3.5
From d30daa883ab27a0acda7c12235608cdaa77e4c77 Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@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
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers