1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

Make TAP tests work on Windows.

On Windows, use listen_address=127.0.0.1 to allow TCP connections. We were
already using "pg_regress --config-auth" to set up HBA appropriately. The
standard_initdb helper function now sets up the server's
unix_socket_directories or listen_addresses in the config file, so that
they don't need to be specified in the pg_ctl command line anymore. That
way, the pg_ctl invocations in test programs don't need to differ between
Windows and Unix.

Add another helper function to configure the server's pg_hba.conf to allow
replication connections. The configuration is done similarly to "pg_regress
--config-auth": trust on domain sockets on Unix, and SSPI authentication on
Windows.

Replace calls to "cat" and "touch" programs with built-in perl code, as
those programs don't normally exist on Windows.

Add instructions in the docs on how to install IPC::Run on Windows. Adjust
vcregress.pl to not replace PERL5LIB completely in vcregress.pl, because
otherwise cannot install IPC::Run in a non-standard location easily.

Michael Paquier, reviewed by Noah Misch, some additional tweaking by me.
This commit is contained in:
Heikki Linnakangas
2015-07-29 19:17:02 +03:00
parent 5f1066074c
commit 13d856e177
9 changed files with 232 additions and 101 deletions

View File

@ -3,11 +3,13 @@ package TestLib;
use strict;
use warnings;
use Config;
use Exporter 'import';
our @EXPORT = qw(
tempdir
tempdir_short
standard_initdb
configure_hba_for_replication
start_test_server
restart_test_server
psql
@ -119,29 +121,74 @@ sub tempdir_short
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
{
my $pgdata = shift;
system_or_bail('initdb', '-D', "$pgdata", '-A' , 'trust', '-N');
system_or_bail("$ENV{top_builddir}/src/test/regress/pg_regress",
'--config-auth', $pgdata);
system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
my $tempdir_short = tempdir_short;
open CONF, ">>$pgdata/postgresql.conf";
print CONF "\n# Added by TestLib.pm)\n";
if ($Config{osname} eq "MSWin32")
{
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;
$ENV{PGHOST} = ($Config{osname} eq "MSWin32") ? "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 ($Config{osname} ne "MSWin32")
{
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);
# Initialize a new cluster for testing in given directory, and start it.
sub start_test_server
{
my ($tempdir) = @_;
my $ret;
my $tempdir_short = tempdir_short;
print("### Starting test server in $tempdir\n");
standard_initdb "$tempdir/pgdata";
$ret = system_log('pg_ctl', '-D', "$tempdir/pgdata", '-w', '-l',
"$log_path/postmaster.log", '-o',
"--fsync=off -k \"$tempdir_short\" --listen-addresses='' --log-statement=all",
'start');
"$log_path/postmaster.log", '-o', "--fsync=off --log-statement=all",
'start');
if ($ret != 0)
{
print "# pg_ctl failed; logfile:\n";
@ -149,7 +196,6 @@ sub start_test_server
BAIL_OUT("pg_ctl failed");
}
$ENV{PGHOST} = $tempdir_short;
$test_server_datadir = "$tempdir/pgdata";
$test_server_logfile = "$log_path/postmaster.log";
}
@ -242,7 +288,17 @@ sub command_exit_is
print("# Running: " . join(" ", @{$cmd}) ."\n");
my $h = start $cmd;
$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
@ -295,7 +351,7 @@ sub issues_sql_like
truncate $test_server_logfile, 0;
my $result = run_log($cmd);
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");
}