From 00aa3b1f9c621d12c47f8e2e5f40a0a1ef0b0ce3 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 8 Aug 2019 11:19:04 +0200 Subject: [PATCH v2 6/7] Fix handling of Unix-domain sockets on Windows in tests Don't run the tests using Unix-domain sockets by default on Windows, but allow enabling it explicitly by setting the environment variable PG_TEST_USE_UNIX_SOCKETS. --- src/bin/pg_ctl/t/001_start_stop.pl | 2 +- src/test/authentication/t/001_password.pl | 7 +++---- src/test/authentication/t/002_saslprep.pl | 7 +++---- src/test/perl/PostgresNode.pm | 4 ++-- src/test/perl/TestLib.pm | 8 +++++++- src/test/regress/pg_regress.c | 14 ++++++++++---- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.pl index e5d46a6f25..70748354a6 100644 --- a/src/bin/pg_ctl/t/001_start_stop.pl +++ b/src/bin/pg_ctl/t/001_start_stop.pl @@ -27,7 +27,7 @@ print $conf TestLib::slurp_file($ENV{TEMP_CONFIG}) if defined $ENV{TEMP_CONFIG}; -if (!$windows_os) +if ($use_unix_sockets) { print $conf "listen_addresses = ''\n"; print $conf "unix_socket_directories = '$tempdir_short'\n"; diff --git a/src/test/authentication/t/001_password.pl b/src/test/authentication/t/001_password.pl index 3a3b0eb7e8..f69d6dcf3f 100644 --- a/src/test/authentication/t/001_password.pl +++ b/src/test/authentication/t/001_password.pl @@ -3,17 +3,16 @@ # - Plain # - MD5-encrypted # - SCRAM-encrypted -# This test cannot run on Windows as Postgres cannot be set up with Unix -# sockets and needs to go through SSPI. +# This test can only run with Unix-domain sockets. use strict; use warnings; use PostgresNode; use TestLib; use Test::More; -if ($windows_os) +if (!$use_unix_sockets) { - plan skip_all => "authentication tests cannot run on Windows"; + plan skip_all => "authentication tests cannot run without Unix-domain sockets"; } else { diff --git a/src/test/authentication/t/002_saslprep.pl b/src/test/authentication/t/002_saslprep.pl index c4b335c45f..bf57933d94 100644 --- a/src/test/authentication/t/002_saslprep.pl +++ b/src/test/authentication/t/002_saslprep.pl @@ -1,16 +1,15 @@ # Test password normalization in SCRAM. # -# This test cannot run on Windows as Postgres cannot be set up with Unix -# sockets and needs to go through SSPI. +# This test can only run with Unix-domain sockets. use strict; use warnings; use PostgresNode; use TestLib; use Test::More; -if ($windows_os) +if (!$use_unix_sockets) { - plan skip_all => "authentication tests cannot run on Windows"; + plan skip_all => "authentication tests cannot run without Unix-domain sockets"; } else { diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index 270bd6c856..04d9e6bde1 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -116,7 +116,7 @@ INIT # Set PGHOST for backward compatibility. This doesn't work for own_host # nodes, so prefer to not rely on this when writing new tests. - $use_tcp = $TestLib::windows_os; + $use_tcp = !$TestLib::use_unix_sockets; $test_localhost = "127.0.0.1"; $last_host_assigned = 1; $test_pghost = $use_tcp ? $test_localhost : TestLib::tempdir_short; @@ -387,7 +387,7 @@ sub set_replication_conf open my $hba, '>>', "$pgdata/pg_hba.conf"; print $hba "\n# Allow replication (set up by PostgresNode.pm)\n"; - if ($TestLib::windows_os) + if ($TestLib::windows_os && !$TestLib::use_unix_sockets) { print $hba "host replication all $test_localhost/32 sspi include_realm=1 map=regress\n"; diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 6195c21c59..a20c3709eb 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -50,9 +50,10 @@ our @EXPORT = qw( command_checks_all $windows_os + $use_unix_sockets ); -our ($windows_os, $tmp_check, $log_path, $test_logfile); +our ($windows_os, $use_unix_sockets, $tmp_check, $log_path, $test_logfile); BEGIN { @@ -79,6 +80,11 @@ BEGIN # Must be set early $windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys'; + + # Specifies whether to use Unix sockets for test setups. On + # Windows we don't use them by default since it's not universally + # supported, but it can be overridden if desired. + $use_unix_sockets = (!$windows_os || $ENV{PG_TEST_USE_UNIX_SOCKETS} ne ''); } INIT diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index 117a9544ea..22b40304ce 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -102,11 +102,10 @@ static char *logfilename; static FILE *logfile; static char *difffilename; static const char *sockdir; -#ifdef HAVE_UNIX_SOCKETS +static bool use_unix_sockets; static const char *temp_sockdir; static char sockself[MAXPGPATH]; static char socklock[MAXPGPATH]; -#endif static _resultmap *resultmap = NULL; @@ -2117,10 +2116,17 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc atexit(stop_postmaster); #ifndef HAVE_UNIX_SOCKETS - /* no unix domain sockets available, so change default */ - hostname = "localhost"; + use_unix_sockets = false; +#elif defined(WIN32) + use_unix_sockets = getenv("PG_TEST_USE_UNIX_SOCKETS") ? true : false; +#else + use_unix_sockets = true; #endif + if (!use_unix_sockets) + /* no unix domain sockets available, so change default */ + hostname = "localhost"; + /* * We call the initialization function here because that way we can set * default parameters and let them be overwritten by the commandline. -- 2.22.0