Commit f545d233 authored by Peter Eisentraut's avatar Peter Eisentraut

Use a separate temporary directory for the Unix-domain socket

Creating the Unix-domain socket in the build directory can run into
name-length limitations.  Therefore, create the socket file in the
default temporary directory of the operating system.  Keep the temporary
data directory etc. in the build tree.
parent 0490db62
...@@ -4,6 +4,7 @@ use TestLib; ...@@ -4,6 +4,7 @@ use TestLib;
use Test::More tests => 10; use Test::More tests => 10;
my $tempdir = TestLib::tempdir; my $tempdir = TestLib::tempdir;
my $tempdir_short = TestLib::tempdir_short;
program_help_ok('pg_ctl'); program_help_ok('pg_ctl');
program_version_ok('pg_ctl'); program_version_ok('pg_ctl');
...@@ -12,7 +13,7 @@ program_options_handling_ok('pg_ctl'); ...@@ -12,7 +13,7 @@ program_options_handling_ok('pg_ctl');
command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data" ], 'pg_ctl initdb'); command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data" ], 'pg_ctl initdb');
open CONF, ">>$tempdir/data/postgresql.conf"; open CONF, ">>$tempdir/data/postgresql.conf";
print CONF "listen_addresses = ''\n"; print CONF "listen_addresses = ''\n";
print CONF "unix_socket_directories = '$tempdir'\n"; print CONF "unix_socket_directories = '$tempdir_short'\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');
......
...@@ -4,11 +4,12 @@ use TestLib; ...@@ -4,11 +4,12 @@ use TestLib;
use Test::More tests => 2; use Test::More tests => 2;
my $tempdir = TestLib::tempdir; my $tempdir = TestLib::tempdir;
my $tempdir_short = TestLib::tempdir_short;
system_or_bail "initdb -D $tempdir/data -A trust >/dev/null"; system_or_bail "initdb -D $tempdir/data -A trust >/dev/null";
open CONF, ">>$tempdir/data/postgresql.conf"; open CONF, ">>$tempdir/data/postgresql.conf";
print CONF "listen_addresses = ''\n"; print CONF "listen_addresses = ''\n";
print CONF "unix_socket_directories = '$tempdir'\n"; print CONF "unix_socket_directories = '$tempdir_short'\n";
close CONF; close CONF;
command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ], command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ],
......
...@@ -6,6 +6,7 @@ use warnings; ...@@ -6,6 +6,7 @@ use warnings;
use Exporter 'import'; use Exporter 'import';
our @EXPORT = qw( our @EXPORT = qw(
tempdir tempdir
tempdir_short
start_test_server start_test_server
restart_test_server restart_test_server
psql psql
...@@ -65,6 +66,13 @@ sub tempdir ...@@ -65,6 +66,13 @@ sub tempdir
return File::Temp::tempdir('tmp_testXXXX', DIR => $ENV{TESTDIR} || cwd(), CLEANUP => 1); return File::Temp::tempdir('tmp_testXXXX', DIR => $ENV{TESTDIR} || cwd(), CLEANUP => 1);
} }
sub tempdir_short
{
# Use a separate temp dir outside the build tree for the
# Unix-domain socket, to avoid file name length issues.
return File::Temp::tempdir(CLEANUP => 1);
}
my ($test_server_datadir, $test_server_logfile); my ($test_server_datadir, $test_server_logfile);
sub start_test_server sub start_test_server
...@@ -72,10 +80,12 @@ sub start_test_server ...@@ -72,10 +80,12 @@ sub start_test_server
my ($tempdir) = @_; my ($tempdir) = @_;
my $ret; my $ret;
my $tempdir_short = tempdir_short;
system "initdb -D $tempdir/pgdata -A trust -N >/dev/null"; system "initdb -D $tempdir/pgdata -A trust -N >/dev/null";
$ret = system 'pg_ctl', '-D', "$tempdir/pgdata", '-s', '-w', '-l', $ret = system 'pg_ctl', '-D', "$tempdir/pgdata", '-s', '-w', '-l',
"$tempdir/logfile", '-o', "$tempdir/logfile", '-o',
"--fsync=off -k $tempdir --listen-addresses='' --log-statement=all", "--fsync=off -k $tempdir_short --listen-addresses='' --log-statement=all",
'start'; 'start';
if ($ret != 0) if ($ret != 0)
...@@ -84,7 +94,7 @@ sub start_test_server ...@@ -84,7 +94,7 @@ sub start_test_server
BAIL_OUT("pg_ctl failed"); BAIL_OUT("pg_ctl failed");
} }
$ENV{PGHOST} = $tempdir; $ENV{PGHOST} = $tempdir_short;
$test_server_datadir = "$tempdir/pgdata"; $test_server_datadir = "$tempdir/pgdata";
$test_server_logfile = "$tempdir/logfile"; $test_server_logfile = "$tempdir/logfile";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment