1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-22 02:52:08 +03:00

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>
This commit is contained in:
Peter Eisentraut
2017-09-05 12:22:33 -04:00
parent 5e8304fdce
commit 90627cf98a
7 changed files with 61 additions and 15 deletions

View File

@ -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