1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-05 07:41:25 +03:00

Back-patch fixes to make TAP tests work on Windows.

This back-ports commit 13d856e177 and assorted followon patches
into 9.4 and 9.5.  9.5 and HEAD are now substantially identical in all
the files touched by this commit, except that 010_pg_basebackup.pl has
a few more tests related to the new --slot option.  9.4 has many fewer
TAP tests, but the test infrastructure files are substantially the same,
with the exception that 9.4 lacks the single-tmp-install infrastructure
introduced in 9.5 (commit dcae5facca).

The primary motivation for this patch is to ensure that TAP test case
fixes can be back-patched without hazards of the kind seen in commits
34557f544/06dd4b44f.  In principle it should also make the world safe
for running the TAP tests in the buildfarm in these branches; although
we might want to think about back-porting dcae5facca to 9.4 if
we're going to do that for real, because the TAP tests are quite disk
space hungry without it.

Michael Paquier did the back-porting work; original patches were by
him and assorted other people.
This commit is contained in:
Tom Lane
2015-11-17 14:10:24 -05:00
parent a408bd58a6
commit 331828b754
11 changed files with 300 additions and 113 deletions

View File

@@ -439,6 +439,7 @@ $ENV{CONFIG}="Debug";
<userinput>vcregress modulescheck</userinput> <userinput>vcregress modulescheck</userinput>
<userinput>vcregress ecpgcheck</userinput> <userinput>vcregress ecpgcheck</userinput>
<userinput>vcregress isolationcheck</userinput> <userinput>vcregress isolationcheck</userinput>
<userinput>vcregress tapcheck</userinput>
<userinput>vcregress upgradecheck</userinput> <userinput>vcregress upgradecheck</userinput>
</screen> </screen>
@@ -451,6 +452,29 @@ $ENV{CONFIG}="Debug";
For more information about the regression tests, see For more information about the regression tests, see
<xref linkend="regress">. <xref linkend="regress">.
</para> </para>
<para>
Running the TAP regression tests, with "vcregress tapcheck", requires an
additional Perl module to be installed:
<variablelist>
<varlistentry>
<term><productname>IPC::Run</productname></term>
<listitem><para>
As of this writing, <literal>IPC::Run</> is not included in the
ActiveState Perl installation, nor in the ActiveState Perl Package
Manager (PPM) library. To install, download the
<filename>IPC-Run-&lt;version&gt;.tar.gz</> source archive from CPAN,
at <ulink url="http://search.cpan.org/dist/IPC-Run/"></>, and
uncompress. Edit the <filename>buildenv.pl</> file, and add a PERL5LIB
variable to point to the <filename>lib</> subdirectory from the
extracted archive. For example:
<programlisting>
$ENV{PERL5LIB}=$ENV{PERL5LIB} . ';c:\IPC-Run-0.94\lib';
</programlisting>
</para></listitem>
</varlistentry>
</variablelist>
</para>
</sect2> </sect2>
<sect2> <sect2>

View File

@@ -352,12 +352,12 @@ ifeq ($(enable_tap_tests),yes)
define prove_installcheck define prove_installcheck
rm -rf $(CURDIR)/tmp_check/log rm -rf $(CURDIR)/tmp_check/log
cd $(srcdir) && TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl cd $(srcdir) && TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl
endef endef
define prove_check define prove_check
rm -rf $(CURDIR)/tmp_check/log rm -rf $(CURDIR)/tmp_check/log
cd $(srcdir) && TESTDIR='$(CURDIR)' $(with_temp_install) PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl cd $(srcdir) && TESTDIR='$(CURDIR)' $(with_temp_install) PGPORT='6$(DEF_PGPORT)' PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl
endef endef
else else

View File

@@ -1,8 +1,9 @@
use strict; use strict;
use warnings; use warnings;
use Cwd; use Cwd;
use Config;
use TestLib; use TestLib;
use Test::More tests => 35; use Test::More tests => 46;
program_help_ok('pg_basebackup'); program_help_ok('pg_basebackup');
program_version_ok('pg_basebackup'); program_version_ok('pg_basebackup');
@@ -25,11 +26,7 @@ if (open BADCHARS, ">>$tempdir/pgdata/FOO\xe0\xe0\xe0BAR")
close BADCHARS; close BADCHARS;
} }
open HBA, ">>$tempdir/pgdata/pg_hba.conf"; configure_hba_for_replication "$tempdir/pgdata";
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";
close HBA;
system_or_bail 'pg_ctl', '-D', "$tempdir/pgdata", 'reload'; system_or_bail 'pg_ctl', '-D', "$tempdir/pgdata", 'reload';
command_fails( command_fails(
@@ -37,6 +34,7 @@ command_fails(
'pg_basebackup fails because of WAL configuration'); 'pg_basebackup fails because of WAL configuration');
open CONF, ">>$tempdir/pgdata/postgresql.conf"; open CONF, ">>$tempdir/pgdata/postgresql.conf";
print CONF "max_replication_slots = 10\n";
print CONF "max_wal_senders = 10\n"; print CONF "max_wal_senders = 10\n";
print CONF "wal_level = archive\n"; print CONF "wal_level = archive\n";
close CONF; close CONF;
@@ -46,6 +44,10 @@ command_ok([ 'pg_basebackup', '-D', "$tempdir/backup" ],
'pg_basebackup runs'); 'pg_basebackup runs');
ok(-f "$tempdir/backup/PG_VERSION", 'backup was created'); ok(-f "$tempdir/backup/PG_VERSION", 'backup was created');
is_deeply([sort(slurp_dir("$tempdir/backup/pg_xlog/"))],
[sort qw(. .. archive_status)],
'no WAL files copied');
command_ok( command_ok(
[ 'pg_basebackup', '-D', "$tempdir/backup2", '--xlogdir', [ 'pg_basebackup', '-D', "$tempdir/backup2", '--xlogdir',
"$tempdir/xlog2" ], "$tempdir/xlog2" ],
@@ -57,61 +59,6 @@ command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup", '-Ft' ],
'tar format'); 'tar format');
ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created'); ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created');
my $superlongname = "superlongname_" . ("x" x 100);
system_or_bail 'touch', "$tempdir/pgdata/$superlongname";
command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l1", '-Ft' ],
'pg_basebackup tar with long name fails');
unlink "$tempdir/pgdata/$superlongname";
# 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
# the 99 character length limit.
my $shorter_tempdir = tempdir_short . "/tempdir";
symlink "$tempdir", $shorter_tempdir;
mkdir "$tempdir/tblspc1";
psql 'postgres',
"CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';";
psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;";
command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft' ],
'tar format with tablespaces');
ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created');
my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar";
is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');
command_fails(
[ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp' ],
'plain format with tablespaces fails without tablespace mapping');
command_ok(
[ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp',
"-T$shorter_tempdir/tblspc1=$tempdir/tbackup/tblspc1" ],
'plain format with tablespaces succeeds with tablespace mapping');
ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated');
opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die;
ok( ( grep {
-l "$tempdir/backup1/pg_tblspc/$_"
and readlink "$tempdir/backup1/pg_tblspc/$_" eq
"$tempdir/tbackup/tblspc1"
} readdir($dh)),
"tablespace symlink was updated");
closedir $dh;
mkdir "$tempdir/tbl=spc2";
psql 'postgres', "DROP TABLE test1;";
psql 'postgres', "DROP TABLESPACE tblspc1;";
psql 'postgres',
"CREATE TABLESPACE tblspc2 LOCATION '$shorter_tempdir/tbl=spc2';";
command_ok(
[ 'pg_basebackup', '-D', "$tempdir/backup3", '-Fp',
"-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( command_fails(
[ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T=/foo" ], [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T=/foo" ],
'-T with empty old directory fails'); '-T with empty old directory fails');
@@ -132,9 +79,93 @@ command_fails(
[ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo" ], [ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo" ],
'-T with invalid format fails'); '-T with invalid format fails');
mkdir "$tempdir/$superlongname"; # Tar format doesn't support filenames longer than 100 bytes.
psql 'postgres', my $superlongname = "superlongname_" . ("x" x 100);
"CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';"; my $superlongpath = "$tempdir/pgdata/$superlongname";
command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ],
'pg_basebackup tar with long symlink target'); open FILE, ">$superlongpath" or die "unable to create file $superlongpath";
psql 'postgres', "DROP TABLESPACE tblspc3;"; close FILE;
command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l1", '-Ft' ],
'pg_basebackup tar with long name fails');
unlink "$tempdir/pgdata/$superlongname";
# The following tests test symlinks. Windows doesn't have symlinks, so
# skip on Windows.
SKIP: {
skip "symlinks not supported on Windows", 10 if ($windows_os);
# 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
# the 99 character length limit.
my $shorter_tempdir = tempdir_short . "/tempdir";
symlink "$tempdir", $shorter_tempdir;
mkdir "$tempdir/tblspc1";
psql 'postgres',
"CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';";
psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;";
command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft' ],
'tar format with tablespaces');
ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created');
my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar";
is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');
command_fails(
[ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp' ],
'plain format with tablespaces fails without tablespace mapping');
command_ok(
[ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp',
"-T$shorter_tempdir/tblspc1=$tempdir/tbackup/tblspc1" ],
'plain format with tablespaces succeeds with tablespace mapping');
ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated');
opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die;
ok( ( grep {
-l "$tempdir/backup1/pg_tblspc/$_"
and readlink "$tempdir/backup1/pg_tblspc/$_" eq
"$tempdir/tbackup/tblspc1"
} readdir($dh)),
"tablespace symlink was updated");
closedir $dh;
mkdir "$tempdir/tbl=spc2";
psql 'postgres', "DROP TABLE test1;";
psql 'postgres', "DROP TABLESPACE tblspc1;";
psql 'postgres',
"CREATE TABLESPACE tblspc2 LOCATION '$shorter_tempdir/tbl=spc2';";
command_ok(
[ 'pg_basebackup', '-D', "$tempdir/backup3", '-Fp',
"-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;";
mkdir "$tempdir/$superlongname";
psql 'postgres',
"CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';";
command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ],
'pg_basebackup tar with long symlink target');
psql 'postgres', "DROP TABLESPACE tblspc3;";
}
command_ok([ 'pg_basebackup', '-D', "$tempdir/backupR", '-R' ],
'pg_basebackup -R runs');
ok(-f "$tempdir/backupR/recovery.conf", 'recovery.conf was created');
my $recovery_conf = slurp_file "$tempdir/backupR/recovery.conf";
# using a character class for the final "'" here works around an apparent
# bug in several version of the Msys DTK perl
like($recovery_conf, qr/^standby_mode = 'on[']$/m, 'recovery.conf sets standby_mode');
like($recovery_conf, qr/^primary_conninfo = '.*port=$ENV{PGPORT}.*'$/m, 'recovery.conf sets primary_conninfo');
command_ok([ 'pg_basebackup', '-D', "$tempdir/backupxf", '-X', 'fetch' ],
'pg_basebackup -X fetch runs');
ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_xlog")), 'WAL files copied');
command_ok([ 'pg_basebackup', '-D', "$tempdir/backupxs", '-X', 'stream' ],
'pg_basebackup -X stream runs');
ok(grep(/^[0-9A-F]{24}$/, slurp_dir("$tempdir/backupxf/pg_xlog")), 'WAL files copied');
command_fails([ 'pg_basebackup', '-D', "$tempdir/fail", '-S', 'slot1' ],
'pg_basebackup with replication slot fails without -X stream');
command_fails([ 'pg_basebackup', '-D', "$tempdir/backupxs_sl_fail", '-X', 'stream', '-S', 'slot1' ],
'pg_basebackup fails with nonexistent replication slot');

View File

@@ -1,5 +1,6 @@
use strict; use strict;
use warnings; use warnings;
use Config;
use TestLib; use TestLib;
use Test::More tests => 17; use Test::More tests => 17;
@@ -16,13 +17,20 @@ command_exit_is([ 'pg_ctl', 'start', '-D', "$tempdir/nonexistent" ],
command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data", '-o', '-N' ], command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data", '-o', '-N' ],
'pg_ctl initdb'); 'pg_ctl initdb');
command_ok( command_ok(
[ "$ENV{top_builddir}/src/test/regress/pg_regress", '--config-auth', [ $ENV{PG_REGRESS}, '--config-auth',
"$tempdir/data" ], "$tempdir/data" ],
'configure authentication'); 'configure authentication');
open CONF, ">>$tempdir/data/postgresql.conf"; open CONF, ">>$tempdir/data/postgresql.conf";
print CONF "listen_addresses = ''\n";
print CONF "unix_socket_directories = '$tempdir_short'\n";
print CONF "fsync = off\n"; print CONF "fsync = off\n";
if (! $windows_os)
{
print CONF "listen_addresses = ''\n";
print CONF "unix_socket_directories = '$tempdir_short'\n";
}
else
{
print CONF "listen_addresses = '127.0.0.1'\n";
}
close CONF; close CONF;
command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ], command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ],
'pg_ctl start -w'); 'pg_ctl start -w');

View File

@@ -10,10 +10,6 @@ command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/nonexistent" ],
4, 'pg_ctl status with nonexistent directory'); 4, 'pg_ctl status with nonexistent directory');
standard_initdb "$tempdir/data"; standard_initdb "$tempdir/data";
open CONF, ">>$tempdir/data/postgresql.conf";
print CONF "listen_addresses = ''\n";
print CONF "unix_socket_directories = '$tempdir_short'\n";
close CONF;
command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ], command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ],
3, 'pg_ctl status with server not running'); 3, 'pg_ctl status with server not running');

View File

@@ -40,8 +40,9 @@ use warnings;
use TestLib; use TestLib;
use Test::More; use Test::More;
use Config;
use File::Copy; use File::Copy;
use File::Path qw(remove_tree); use File::Path qw(rmtree);
use IPC::Run qw(run start); use IPC::Run qw(run start);
use Exporter 'import'; use Exporter 'import';
@@ -72,8 +73,6 @@ our $test_standby_datadir = "$tmp_check/data_standby";
my $port_master = $ENV{PGPORT}; my $port_master = $ENV{PGPORT};
my $port_standby = $port_master + 1; my $port_standby = $port_master + 1;
my $tempdir_short;
my $connstr_master = "port=$port_master"; my $connstr_master = "port=$port_master";
my $connstr_standby = "port=$port_standby"; my $connstr_standby = "port=$port_standby";
@@ -121,6 +120,7 @@ sub check_query
} }
else else
{ {
$stdout =~ s/\r//g if $Config{osname} eq 'msys';
is($stdout, $expected_stdout, "$test_name: query result matches"); is($stdout, $expected_stdout, "$test_name: query result matches");
} }
} }
@@ -140,6 +140,7 @@ sub poll_query_until
my $result = run $cmd, '>', \$stdout, '2>', \$stderr; my $result = run $cmd, '>', \$stdout, '2>', \$stderr;
chomp($stdout); chomp($stdout);
$stdout =~ s/\r//g if $Config{osname} eq 'msys';
if ($stdout eq "t") if ($stdout eq "t")
{ {
return 1; return 1;
@@ -167,10 +168,8 @@ sub append_to_file
sub setup_cluster sub setup_cluster
{ {
$tempdir_short = tempdir_short;
# Initialize master, data checksums are mandatory # Initialize master, data checksums are mandatory
remove_tree($test_master_datadir); rmtree($test_master_datadir);
standard_initdb($test_master_datadir); standard_initdb($test_master_datadir);
# Custom parameters for master's postgresql.conf # Custom parameters for master's postgresql.conf
@@ -188,10 +187,7 @@ max_connections = 10
)); ));
# Accept replication connections on master # Accept replication connections on master
append_to_file( configure_hba_for_replication $test_master_datadir;
"$test_master_datadir/pg_hba.conf", qq(
local replication all trust
));
} }
sub start_master sub start_master
@@ -199,19 +195,17 @@ sub start_master
system_or_bail('pg_ctl' , '-w', system_or_bail('pg_ctl' , '-w',
'-D' , $test_master_datadir, '-D' , $test_master_datadir,
'-l', "$log_path/master.log", '-l', "$log_path/master.log",
"-o", "-k $tempdir_short --listen-addresses='' -p $port_master", "-o", "-p $port_master", 'start');
'start');
#### Now run the test-specific parts to initialize the master before setting #### Now run the test-specific parts to initialize the master before setting
# up standby # up standby
$ENV{PGHOST} = $tempdir_short;
} }
sub create_standby sub create_standby
{ {
# Set up standby with necessary parameter # Set up standby with necessary parameter
remove_tree $test_standby_datadir; rmtree $test_standby_datadir;
# Base backup is taken with xlog files included # Base backup is taken with xlog files included
system_or_bail('pg_basebackup', '-D', $test_standby_datadir, system_or_bail('pg_basebackup', '-D', $test_standby_datadir,
@@ -226,8 +220,7 @@ recovery_target_timeline='latest'
# Start standby # Start standby
system_or_bail('pg_ctl', '-w', '-D', $test_standby_datadir, system_or_bail('pg_ctl', '-w', '-D', $test_standby_datadir,
'-l', "$log_path/standby.log", '-l', "$log_path/standby.log",
'-o', "-k $tempdir_short --listen-addresses='' -p $port_standby", '-o', "-p $port_standby", 'start');
'start');
# The standby may have WAL to apply before it matches the primary. That # The standby may have WAL to apply before it matches the primary. That
# is fine, because no test examines the standby before promotion. # is fine, because no test examines the standby before promotion.
@@ -265,7 +258,7 @@ sub run_pg_rewind
my $test_mode = shift; my $test_mode = shift;
# Stop the master and be ready to perform the rewind # Stop the master and be ready to perform the rewind
system_or_bail('pg_ctl', '-D', $test_master_datadir, 'stop', '-m', 'fast'); system_or_bail('pg_ctl', '-D', $test_master_datadir, '-m', 'fast', 'stop');
# At this point, the rewind processing is ready to run. # At this point, the rewind processing is ready to run.
# We now have a very simple scenario with a few diverged WAL record. # We now have a very simple scenario with a few diverged WAL record.
@@ -282,8 +275,8 @@ sub run_pg_rewind
{ {
# Do rewind using a local pgdata as source # Do rewind using a local pgdata as source
# Stop the master and be ready to perform the rewind # Stop the master and be ready to perform the rewind
system_or_bail('pg_ctl', '-D', $test_standby_datadir, 'stop', system_or_bail('pg_ctl', '-D', $test_standby_datadir,
'-m', 'fast'); '-m', 'fast', 'stop');
command_ok(['pg_rewind', command_ok(['pg_rewind',
"--debug", "--debug",
"--source-pgdata=$test_standby_datadir", "--source-pgdata=$test_standby_datadir",
@@ -294,6 +287,7 @@ sub run_pg_rewind
{ {
# Do rewind using a remote connection as source # Do rewind using a remote connection as source
command_ok(['pg_rewind', command_ok(['pg_rewind',
"--debug",
"--source-server", "--source-server",
"port=$port_standby dbname=postgres", "port=$port_standby dbname=postgres",
"--target-pgdata=$test_master_datadir"], "--target-pgdata=$test_master_datadir"],
@@ -321,8 +315,7 @@ recovery_target_timeline='latest'
# Restart the master to check that rewind went correctly # Restart the master to check that rewind went correctly
system_or_bail('pg_ctl', '-w', '-D', $test_master_datadir, system_or_bail('pg_ctl', '-w', '-D', $test_master_datadir,
'-l', "$log_path/master.log", '-l', "$log_path/master.log",
'-o', "-k $tempdir_short --listen-addresses='' -p $port_master", '-o', "-p $port_master", 'start');
'start');
#### Now run the test-specific parts to check the result #### Now run the test-specific parts to check the result
} }

View File

@@ -4,9 +4,18 @@
use strict; use strict;
use warnings; use warnings;
use File::Copy; use File::Copy;
use File::Path qw(remove_tree); use File::Path qw(rmtree);
use TestLib; use TestLib;
use Test::More tests => 4; use Test::More;
if ($windows_os)
{
plan skip_all => 'symlinks not supported on Windows';
exit;
}
else
{
plan tests => 4;
}
use RewindTest; use RewindTest;
@@ -16,7 +25,7 @@ sub run_test
my $master_xlogdir = "$tmp_check/xlog_master"; my $master_xlogdir = "$tmp_check/xlog_master";
remove_tree($master_xlogdir); rmtree($master_xlogdir);
RewindTest::setup_cluster(); RewindTest::setup_cluster();
# turn pg_xlog into a symlink # turn pg_xlog into a symlink

View File

@@ -20,6 +20,7 @@ sub PRINT {
my $ok = 1; my $ok = 1;
for my $fh (@$self) { for my $fh (@$self) {
print $fh @_ or $ok = 0; print $fh @_ or $ok = 0;
$fh->flush or $ok = 0;
} }
return $ok; return $ok;
} }

View File

@@ -9,9 +9,12 @@ our @EXPORT = qw(
tempdir tempdir
tempdir_short tempdir_short
standard_initdb standard_initdb
configure_hba_for_replication
start_test_server start_test_server
restart_test_server restart_test_server
psql psql
slurp_dir
slurp_file
system_or_bail system_or_bail
system_log system_log
run_log run_log
@@ -121,34 +124,75 @@ sub tempdir_short
return File::Temp::tempdir(CLEANUP => 1); return File::Temp::tempdir(CLEANUP => 1);
} }
# Initialize a new cluster for testing.
#
# The PGHOST environment variable is set to connect to the new cluster.
#
# Authentication is set up so that only the current OS user can access the
# cluster. On Unix, we use Unix domain socket connections, with the socket in
# a directory that's only accessible to the current user to ensure that.
# On Windows, we use SSPI authentication to ensure the same (by pg_regress
# --config-auth).
sub standard_initdb sub standard_initdb
{ {
my $pgdata = shift; my $pgdata = shift;
system_or_bail('initdb', '-D', "$pgdata", '-A' , 'trust', '-N'); system_or_bail('initdb', '-D', "$pgdata", '-A' , 'trust', '-N');
system_or_bail("$ENV{top_builddir}/src/test/regress/pg_regress", system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
'--config-auth', $pgdata);
my $tempdir_short = tempdir_short;
open CONF, ">>$pgdata/postgresql.conf"; open CONF, ">>$pgdata/postgresql.conf";
print CONF "\n# Added by TestLib.pm)\n"; print CONF "\n# Added by TestLib.pm)\n";
print CONF "fsync = off\n"; print CONF "fsync = off\n";
if ($windows_os)
{
print CONF "listen_addresses = '127.0.0.1'\n";
}
else
{
print CONF "unix_socket_directories = '$tempdir_short'\n";
print CONF "listen_addresses = ''\n";
}
close CONF; close CONF;
$ENV{PGHOST} = $windows_os ? "127.0.0.1" : $tempdir_short;
}
# Set up the cluster to allow replication connections, in the same way that
# standard_initdb does for normal connections.
sub configure_hba_for_replication
{
my $pgdata = shift;
open HBA, ">>$pgdata/pg_hba.conf";
print HBA "\n# Allow replication (set up by TestLib.pm)\n";
if (! $windows_os)
{
print HBA "local replication all trust\n";
}
else
{
print HBA "host replication all 127.0.0.1/32 sspi include_realm=1 map=regress\n";
}
close HBA;
} }
my ($test_server_datadir, $test_server_logfile); my ($test_server_datadir, $test_server_logfile);
# Initialize a new cluster for testing in given directory, and start it.
sub start_test_server sub start_test_server
{ {
my ($tempdir) = @_; my ($tempdir) = @_;
my $ret; my $ret;
my $tempdir_short = tempdir_short;
print("### Starting test server in $tempdir\n"); print("### Starting test server in $tempdir\n");
standard_initdb "$tempdir/pgdata"; standard_initdb "$tempdir/pgdata";
$ret = system_log('pg_ctl', '-D', "$tempdir/pgdata", '-w', '-l', $ret = system_log('pg_ctl', '-D', "$tempdir/pgdata", '-w', '-l',
"$log_path/postmaster.log", '-o', "$log_path/postmaster.log", '-o', "--log-statement=all",
"-k \"$tempdir_short\" --listen-addresses='' --log-statement=all", 'start');
'start');
if ($ret != 0) if ($ret != 0)
{ {
print "# pg_ctl failed; logfile:\n"; print "# pg_ctl failed; logfile:\n";
@@ -156,7 +200,6 @@ sub start_test_server
BAIL_OUT("pg_ctl failed"); BAIL_OUT("pg_ctl failed");
} }
$ENV{PGHOST} = $tempdir_short;
$test_server_datadir = "$tempdir/pgdata"; $test_server_datadir = "$tempdir/pgdata";
$test_server_logfile = "$log_path/postmaster.log"; $test_server_logfile = "$log_path/postmaster.log";
} }
@@ -180,8 +223,30 @@ END
sub psql sub psql
{ {
my ($dbname, $sql) = @_; my ($dbname, $sql) = @_;
my ($stdout, $stderr);
print("# Running SQL command: $sql\n"); print("# Running SQL command: $sql\n");
run [ 'psql', '-X', '-q', '-d', $dbname, '-f', '-' ], '<', \$sql or die; run [ 'psql', '-X', '-A', '-t', '-q', '-d', $dbname, '-f', '-' ], '<', \$sql, '>', \$stdout, '2>', \$stderr or die;
chomp $stdout;
$stdout =~ s/\r//g if $Config{osname} eq 'msys';
return $stdout;
}
sub slurp_dir
{
my ($dir) = @_;
opendir(my $dh, $dir) or die;
my @direntries = readdir $dh;
closedir $dh;
return @direntries;
}
sub slurp_file
{
local $/;
local @ARGV = @_;
my $contents = <>;
$contents =~ s/\r//g if $Config{osname} eq 'msys';
return $contents;
} }
sub system_or_bail sub system_or_bail
@@ -230,7 +295,17 @@ sub command_exit_is
print("# Running: " . join(" ", @{$cmd}) ."\n"); print("# Running: " . join(" ", @{$cmd}) ."\n");
my $h = start $cmd; my $h = start $cmd;
$h->finish(); $h->finish();
is($h->result(0), $expected, $test_name);
# On Windows, the exit status of the process is returned directly as the
# process's exit code, while on Unix, it's returned in the high bits
# of the exit code (see WEXITSTATUS macro in the standard <sys/wait.h>
# header file). IPC::Run's result function always returns exit code >> 8,
# assuming the Unix convention, which will always return 0 on Windows as
# long as the process was not terminated by an exception. To work around
# that, use $h->full_result on Windows instead.
my $result = ($Config{osname} eq "MSWin32") ?
($h->full_results)[0] : $h->result(0);
is($result, $expected, $test_name);
} }
sub program_help_ok sub program_help_ok
@@ -283,7 +358,7 @@ sub issues_sql_like
truncate $test_server_logfile, 0; truncate $test_server_logfile, 0;
my $result = run_log($cmd); my $result = run_log($cmd);
ok($result, "@$cmd exit code 0"); ok($result, "@$cmd exit code 0");
my $log = `cat '$test_server_logfile'`; my $log = slurp_file($test_server_logfile);
like($log, $expected_sql, "$test_name: SQL found in server log"); like($log, $expected_sql, "$test_name: SQL found in server log");
} }

View File

@@ -88,6 +88,13 @@ if exist src\test\regress\regress.dll del /q src\test\regress\regress.dll
if exist src\test\regress\refint.dll del /q src\test\regress\refint.dll if exist src\test\regress\refint.dll del /q src\test\regress\refint.dll
if exist src\test\regress\autoinc.dll del /q src\test\regress\autoinc.dll if exist src\test\regress\autoinc.dll del /q src\test\regress\autoinc.dll
if exist src\bin\initdb\tmp_check rd /s /q src\bin\initdb\tmp_check
if exist src\bin\pg_basebackup\tmp_check rd /s /q src\bin\pg_basebackup\tmp_check
if exist src\bin\pg_config\tmp_check rd /s /q src\bin\pg_config\tmp_check
if exist src\bin\pg_ctl\tmp_check rd /s /q src\bin\pg_ctl\tmp_check
if exist src\bin\pg_rewind\tmp_check rd /s /q src\bin\pg_rewind\tmp_check
if exist src\bin\scripts\tmp_check rd /s /q src\bin\scripts\tmp_check
REM Clean up datafiles built with contrib REM Clean up datafiles built with contrib
REM cd contrib REM cd contrib
REM for /r %%f in (*.sql) do if exist %%f.in del %%f REM for /r %%f in (*.sql) do if exist %%f.in del %%f

View File

@@ -7,7 +7,9 @@ use strict;
our $config; our $config;
use Cwd; use Cwd;
use File::Basename;
use File::Copy; use File::Copy;
use File::Find ();
use Install qw(Install); use Install qw(Install);
@@ -32,7 +34,7 @@ if (-e "src/tools/msvc/buildenv.pl")
my $what = shift || ""; my $what = shift || "";
if ($what =~ if ($what =~
/^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck)$/i /^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck|tapcheck)$/i
) )
{ {
$what = uc $what; $what = uc $what;
@@ -59,7 +61,7 @@ unless ($schedule)
$schedule = "parallel" if ($what eq 'CHECK' || $what =~ /PARALLEL/); $schedule = "parallel" if ($what eq 'CHECK' || $what =~ /PARALLEL/);
} }
$ENV{PERL5LIB} = "$topdir/src/tools/msvc"; $ENV{PERL5LIB} = "$topdir/src/tools/msvc;$ENV{PERL5LIB}";
my $maxconn = ""; my $maxconn = "";
$maxconn = "--max_connections=$ENV{MAX_CONNECTIONS}" $maxconn = "--max_connections=$ENV{MAX_CONNECTIONS}"
@@ -79,6 +81,7 @@ my %command = (
CONTRIBCHECK => \&contribcheck, CONTRIBCHECK => \&contribcheck,
MODULESCHECK => \&modulescheck, MODULESCHECK => \&modulescheck,
ISOLATIONCHECK => \&isolationcheck, ISOLATIONCHECK => \&isolationcheck,
TAPCHECK => \&tapcheck,
UPGRADECHECK => \&upgradecheck,); UPGRADECHECK => \&upgradecheck,);
my $proc = $command{$what}; my $proc = $command{$what};
@@ -165,6 +168,46 @@ sub isolationcheck
exit $status if $status; exit $status if $status;
} }
sub tapcheck
{
InstallTemp();
my @args = ( "prove", "--verbose", "t/*.pl");
my $mstat = 0;
$ENV{PERL5LIB} = "$topdir/src/test/perl;$ENV{PERL5LIB}";
$ENV{PG_REGRESS} = "$topdir/$Config/pg_regress/pg_regress";
# Find out all the existing TAP tests by looking for t/ directories
# 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)
{
# Like on Unix "make check-world", don't run the SSL test suite
# automatically.
next if ($test_path =~ /\/src\/test\/ssl\//);
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;
$mstat ||= $status;
}
exit $mstat if $mstat;
}
sub plcheck sub plcheck
{ {
chdir "../../pl"; chdir "../../pl";