v6-0005-Allow-using-Unix-domain-sockets-on-Windows-in-tes.patch
text/plain
Filename: v6-0005-Allow-using-Unix-domain-sockets-on-Windows-in-tes.patch
Type: text/plain
Part: 4
Patch
Format: format-patch
Series: patch v6-0005
Subject: Allow using Unix-domain sockets on Windows in tests
| File | + | − |
|---|---|---|
| src/bin/pg_ctl/t/001_start_stop.pl | 1 | 1 |
| src/test/authentication/t/001_password.pl | 3 | 4 |
| src/test/authentication/t/002_saslprep.pl | 3 | 4 |
| src/test/perl/PostgresNode.pm | 2 | 2 |
| src/test/perl/TestLib.pm | 7 | 1 |
| src/test/regress/pg_regress.c | 15 | 6 |
From eb71051830aa4019bb85acdb57372e23e54043ac Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 8 Aug 2019 11:19:04 +0200
Subject: [PATCH v6 5/5] Allow using Unix-domain sockets on Windows in tests
As before, 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.
Previously, the TAP tests were hardcoded to not use Unix-domain
sockets on Windows, where as pg_regress would key off
HAVE_UNIX_SOCKETS, which is no longer a useful distinguisher.
For pg_regress, allow overriding using /tmp for the temporary socket
location by using the TMPDIR environment variable if present, because
/tmp might not exist on Windows.
---
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 | 21 +++++++++++++++------
6 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.pl
index 6a1619e171..b1e419f02e 100644
--- a/src/bin/pg_ctl/t/001_start_stop.pl
+++ b/src/bin/pg_ctl/t/001_start_stop.pl
@@ -29,7 +29,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 5985130e3d..b8d6cc52e9 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 9575268bd7..1d5450758e 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 65ee0425b0..0e6c4819e4 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -83,9 +83,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
{
@@ -117,6 +118,11 @@ BEGIN
require Win32API::File;
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
}
+
+ # 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 || defined $ENV{PG_TEST_USE_UNIX_SOCKETS});
}
=pod
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 92bd28dc5a..b58bd7e49c 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -101,11 +101,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;
@@ -293,7 +292,7 @@ stop_postmaster(void)
* remove the directory. Ignore errors; leaking a temporary directory is
* unimportant. This can run from a signal handler. The code is not
* acceptable in a Windows signal handler (see initdb.c:trapsig()), but
- * Windows is not a HAVE_UNIX_SOCKETS platform.
+ * on Windows, pg_regress does not use Unix sockets by default.
*/
static void
remove_temp(void)
@@ -331,7 +330,7 @@ signal_remove_temp(int signum)
static const char *
make_temp_sockdir(void)
{
- char *template = pg_strdup("/tmp/pg_regress-XXXXXX");
+ char *template = psprintf("%s/pg_regress-XXXXXX", getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
temp_sockdir = mkdtemp(template);
if (temp_sockdir == NULL)
@@ -993,6 +992,9 @@ config_sspi_auth(const char *pgdata, const char *superuser_name)
*ident;
_stringlist *sl;
+ if (use_unix_sockets)
+ return;
+
/* Find out the name of the current OS user */
current_windows_user(&accountname, &domainname);
@@ -2134,10 +2136,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.25.0