summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgregor herrmann <gregoa@debian.org>2022-02-20 16:20:01 +0100
committergregor herrmann <gregoa@debian.org>2022-02-20 16:20:01 +0100
commit4760a85559a14931263c74cf8d4022da8d5caf0f (patch)
tree3513867cfc5629acd3c09013748f03708bfb9a16
parent5d1212b6905e8b006f725485f8d7e999967f55bb (diff)
parent18ab71f2e2d5d1401ee0026d437f068d21119822 (diff)
New upstream version 1.29
-rw-r--r--Changes5
-rw-r--r--META.json10
-rw-r--r--META.yml9
-rw-r--r--README.md4
-rw-r--r--lib/Test/PostgreSQL.pm72
5 files changed, 80 insertions, 20 deletions
diff --git a/Changes b/Changes
index 2c7fd14..cfc55a4 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
Revision history for Perl extension Test::PostgreSQL.
+1.29 2022-02-18T03:26:21Z
+
+1.29 2022-02-18T00:31:54Z
+ - Fix concurrent execution under Yath
+
1.28 2021-03-12T10:50:46Z
- Increment port by random amount when trying to find a good port
- Allow using beta versions
diff --git a/META.json b/META.json
index 3fe59a9..dfd8a06 100644
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
"Toby Corkindale, Kazuho Oku, Peter Mottram, Alex Tokarev, plus various contributors."
],
"dynamic_config" : 0,
- "generated_by" : "Minilla/v3.1.11",
+ "generated_by" : "Minilla/v3.1.15",
"license" : [
"artistic_2"
],
@@ -67,19 +67,21 @@
"provides" : {
"Test::PostgreSQL" : {
"file" : "lib/Test/PostgreSQL.pm",
- "version" : "1.28"
+ "version" : "1.29"
}
},
"release_status" : "stable",
"resources" : {
"homepage" : "https://github.com/TJC/Test-postgresql",
"repository" : {
- "url" : "git://github.com/TJC/Test-postgresql.git",
+ "type" : "git",
+ "url" : "https://github.com/TJC/Test-postgresql.git",
"web" : "https://github.com/TJC/Test-postgresql"
}
},
- "version" : "1.28",
+ "version" : "1.29",
"x_contributors" : [
+ "Alex Tokarev <nohuhu@cpan.org>",
"Alex Tokarev <nohuhu@users.noreply.github.com>",
"Alex Tokarev <tokarev@cpan.org>",
"Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>",
diff --git a/META.yml b/META.yml
index 397524e..df51b27 100644
--- a/META.yml
+++ b/META.yml
@@ -8,7 +8,7 @@ build_requires:
configure_requires:
Module::Build::Tiny: '0.035'
dynamic_config: 0
-generated_by: 'Minilla/v3.1.11, CPAN::Meta::Converter version 2.150010'
+generated_by: 'Minilla/v3.1.15, CPAN::Meta::Converter version 2.150010'
license: artistic_2
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -27,7 +27,7 @@ no_index:
provides:
Test::PostgreSQL:
file: lib/Test/PostgreSQL.pm
- version: '1.28'
+ version: '1.29'
requires:
DBD::Pg: '0'
DBI: '0'
@@ -43,9 +43,10 @@ requires:
perl: '5.014'
resources:
homepage: https://github.com/TJC/Test-postgresql
- repository: git://github.com/TJC/Test-postgresql.git
-version: '1.28'
+ repository: https://github.com/TJC/Test-postgresql.git
+version: '1.29'
x_contributors:
+ - 'Alex Tokarev <nohuhu@cpan.org>'
- 'Alex Tokarev <nohuhu@users.noreply.github.com>'
- 'Alex Tokarev <tokarev@cpan.org>'
- 'Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>'
diff --git a/README.md b/README.md
index 3baf668..80a62b2 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ conflicting TCP ports on localhost.\]
## socket\_dir
-Unix socket directory to use if ["unix\_socket"](#unix_socket) is true. Default is `$basedir/tmp`.
+Unix socket directory to use if ["unix\_socket"](#unix_socket) is true. Default is `$base_dir/tmp`.
## pg\_ctl
@@ -102,7 +102,7 @@ Extra args to be appended to ["initdb\_args"](#initdb_args). Default is empty.
## pg\_config
-Configuration to place in `$basedir/data/postgresql.conf`. Use this to override
+Configuration to place in `$base_dir/data/postgresql.conf`. Use this to override
PostgreSQL configuration defaults, e.g. to speed up PostgreSQL database init
and seeding one might use something like this:
diff --git a/lib/Test/PostgreSQL.pm b/lib/Test/PostgreSQL.pm
index 4195938..839736a 100644
--- a/lib/Test/PostgreSQL.pm
+++ b/lib/Test/PostgreSQL.pm
@@ -13,7 +13,7 @@ use File::Which;
use POSIX qw(SIGQUIT SIGKILL WNOHANG getuid setuid);
use User::pwent;
-our $VERSION = '1.28';
+our $VERSION = '1.29';
our $errstr;
# Deprecate use of %Defaults as we want to remove this package global
@@ -116,7 +116,42 @@ has socket_dir => (
is => "ro",
isa => Str,
lazy => 1,
- default => method () { File::Spec->catdir( $self->base_dir, 'tmp' ) },
+ default => method () {
+ my $dir = File::Spec->catdir( $self->base_dir, 'tmp' );
+
+ # This magic number is based on the Unixy systems limit for
+ # Unix socket path lengths: on Linuxes it is at 108 characters,
+ # MacOS allows no more than 103. Considering that we are
+ # generating a directory path, and the actual socket file name
+ # will be appended to it, 80 characters seemed a safe assumption.
+ if (length $dir > 80) {
+ $self->{_socket_dir} = File::Temp->newdir(
+ 'pgtest_sock.XXXXX',
+
+ # base_dir is preserved if environment variable
+ # TEST_POSTGRESQL_PRESERVE is truthy; this is done
+ # for diagnostics. Socket directory should always
+ # be cleaned up since there is nothing of interest there.
+ CLEANUP => 1,
+ TMPDIR => 1,
+
+ # TODO Come up with something better if this ever cause
+ # any trouble. Straightforward approach with using File::Temp
+ # that consults $TMPDIR environment variable is exactly
+ # the cause for the Unix socket path being too long;
+ # other approaches at sniffing what system we're running on
+ # and what temporary paths are available also fail at various
+ # edge cases, which is exactly the reason File::Temp was created
+ # in the first place. So, no easy answer here; simply falling back
+ # to the timeless default.
+ DIR => '/tmp',
+ );
+
+ $dir = $self->{_socket_dir}->dirname;
+ }
+
+ return $dir;
+ },
);
has initdb => (
@@ -335,6 +370,7 @@ method DEMOLISH($in_global_destruction) {
if (defined $self->pid && $self->_owner_pid == $$) {
$self->stop
}
+ undef $self->{_socket_dir};
return;
}
@@ -389,16 +425,26 @@ method start() {
# It could probably be made more sane.
method _find_port_and_launch() {
my $tries = 10;
- my $port = $self->base_port;
+
srand(); # Re-seed the RNG in case the caller forked the process
+
+ # There is a significant chance that there might be more than
+ # one Test::Postgresql test in flight so we better randomize
+ # the port before even trying to start the first time. Does
+ # no harm if there is no concurrent Postgres running; if there is
+ # then our process will start up a bit faster.
+ my $port = $self->base_port + int(rand(10)) + 1;
+
# try by incrementing port number until PostgreSQL starts
while (1) {
- my $good = try {
+ my $good;
+ try {
+ #warn "Trying to start postgres on port $port...";
$self->_try_start($port);
- 1;
+ $good = 1;
}
catch {
- # warn "Postgres failed to start on port $port\n";
+ #warn "Postgres failed to start on port $port\n";
unless ($tries--) {
die "Failed to start postgres after trying 10 potential ports: $_";
}
@@ -425,12 +471,18 @@ method _try_start($port) {
$port, '-k',
$self->socket_dir)
);
+ #warn "Postgres starting command: " . join(' ', @cmd) . "\n";
$self->setuid_cmd(\@cmd, 1);
my $pid_path = File::Spec->catfile( $self->base_dir, 'data', 'postmaster.pid' );
- open( my $pidfh, '<', $pid_path )
- or die "Failed to open $pid_path: $!";
+ my $pidfh;
+ if (not open($pidfh, '<', $pid_path)) {
+ #open( my $logh, '<', $logfile );
+ #my @loglines = <$logh>;
+ #warn "Postgres log: \n" . join("\n", @loglines);
+ die "Failed to open $pid_path: $!";
+ }
# Note that the file contains several lines; we only want the PID from the first.
my $pid = <$pidfh>;
@@ -792,7 +844,7 @@ conflicting TCP ports on localhost.]
=head2 socket_dir
-Unix socket directory to use if L</unix_socket> is true. Default is C<$basedir/tmp>.
+Unix socket directory to use if L</unix_socket> is true. Default is C<$base_dir/tmp>.
=head2 pg_ctl
@@ -825,7 +877,7 @@ Extra args to be appended to L</initdb_args>. Default is empty.
=head2 pg_config
-Configuration to place in C<$basedir/data/postgresql.conf>. Use this to override
+Configuration to place in C<$base_dir/data/postgresql.conf>. Use this to override
PostgreSQL configuration defaults, e.g. to speed up PostgreSQL database init
and seeding one might use something like this: