aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/PostgresNode.pm
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-09-05 12:22:33 -0400
committerPeter Eisentraut <peter_e@gmx.net>2017-09-05 12:24:06 -0400
commit90627cf98a8e7d0531789391fd798c9bfcc3bc1a (patch)
tree4f5b13996075625850cca581d278e8f2e174751d /src/test/perl/PostgresNode.pm
parent5e8304fdce2d5c41ef7a648ed0a622480f8f0a07 (diff)
downloadpostgresql-90627cf98a8e7d0531789391fd798c9bfcc3bc1a.tar.gz
postgresql-90627cf98a8e7d0531789391fd798c9bfcc3bc1a.zip
Support retaining data dirs on successful TAP tests
This moves the data directories from using temporary directories with randomness in the directory name to a static name, to make it easier to debug. The data directory will be retained if tests fail or the test code dies/exits with failure, and is automatically removed on the next make check. If the environment variable PG_TEST_NOCLEAN is defined, the data directories will be retained regardless of test or exit status. Author: Daniel Gustafsson <daniel@yesql.se>
Diffstat (limited to 'src/test/perl/PostgresNode.pm')
-rw-r--r--src/test/perl/PostgresNode.pm47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm
index d9aeb277d96..3a81c1c60b7 100644
--- a/src/test/perl/PostgresNode.pm
+++ b/src/test/perl/PostgresNode.pm
@@ -86,6 +86,7 @@ use Config;
use Cwd;
use Exporter 'import';
use File::Basename;
+use File::Path qw(rmtree);
use File::Spec;
use File::Temp ();
use IPC::Run;
@@ -100,7 +101,7 @@ our @EXPORT = qw(
get_new_node
);
-our ($test_localhost, $test_pghost, $last_port_assigned, @all_nodes);
+our ($test_localhost, $test_pghost, $last_port_assigned, @all_nodes, $died);
# Windows path to virtual file system root
@@ -149,11 +150,13 @@ sub new
my $self = {
_port => $pgport,
_host => $pghost,
- _basedir => TestLib::tempdir("data_" . $name),
+ _basedir => "$TestLib::tmp_check/t_${testname}_${name}_data",
_name => $name,
_logfile => "$TestLib::log_path/${testname}_${name}.log" };
bless $self, $class;
+ mkdir $self->{_basedir} or
+ BAIL_OUT("could not create data directory \"$self->{_basedir}\": $!");
$self->dump_info;
return $self;
@@ -928,9 +931,24 @@ sub get_new_node
return $node;
}
+# Retain the errno on die() if set, else assume a generic errno of 1.
+# This will instruct the END handler on how to handle artifacts left
+# behind from tests.
+$SIG{__DIE__} = sub
+{
+ if ($!)
+ {
+ $died = $!;
+ }
+ else
+ {
+ $died = 1;
+ }
+};
+
# Automatically shut down any still-running nodes when the test script exits.
# Note that this just stops the postmasters (in the same order the nodes were
-# created in). Temporary PGDATA directories are deleted, in an unspecified
+# created in). Any temporary directories are deleted, in an unspecified
# order, later when the File::Temp objects are destroyed.
END
{
@@ -941,6 +959,13 @@ END
foreach my $node (@all_nodes)
{
$node->teardown_node;
+
+ # skip clean if we are requested to retain the basedir
+ next if defined $ENV{'PG_TEST_NOCLEAN'};
+
+ # clean basedir on clean test invocation
+ $node->clean_node
+ if TestLib::all_tests_passing() && !defined $died && !$exit_code;
}
$? = $exit_code;
@@ -959,6 +984,22 @@ sub teardown_node
my $self = shift;
$self->stop('immediate');
+
+}
+
+=pod
+
+=item $node->clean_node()
+
+Remove the base directory of the node if the node has been stopped.
+
+=cut
+
+sub clean_node
+{
+ my $self = shift;
+
+ rmtree $self->{_basedir} unless defined $self->{_pid};
}
=pod