diff --git a/src/Makefile.global.in b/src/Makefile.global.in index b83f09f..e758831 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -368,9 +368,14 @@ rm -rf $(CURDIR)/tmp_check/log cd $(srcdir) && TESTDIR='$(CURDIR)' $(with_temp_install) PGPORT='6$(DEF_PGPORT)' PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl) endef +define prove_clean +rm -rf $(CURDIR)/tmp_check/t_*_data +endef + else prove_installcheck = @echo "TAP tests not enabled" prove_check = $(prove_installcheck) +prove_clean = $(prove_installcheck) endif # Installation. diff --git a/src/bin/pgbench/Makefile b/src/bin/pgbench/Makefile index 1503d00..de3c7c1 100644 --- a/src/bin/pgbench/Makefile +++ b/src/bin/pgbench/Makefile @@ -46,5 +46,8 @@ maintainer-clean: distclean check: $(prove_check) +check-clean: + $(prove_clean) + installcheck: $(prove_installcheck) diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index 51cbec8..60c306b 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; use File::Spec; use File::Temp (); use IPC::Run; @@ -99,7 +100,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 @@ -148,11 +149,15 @@ 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; + BAIL_OUT("filename collision on node datadir \"$self->{_basedir}\"") + if (-e $self->{_basedir} && !-d _); + rmtree $self->{_basedir}; + mkdir $self->{_basedir} or die; $self->dump_info; return $self; @@ -921,6 +926,21 @@ 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 @@ -934,6 +954,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_TESTS_NOCLEAN'}); + + # clean basedir on clean test invocation + $node->clean_node + unless (!TestLib::all_tests_passing() || defined $died || $exit_code); } $? = $exit_code; @@ -952,6 +979,22 @@ sub teardown_node my $self = shift; $self->stop('immediate'); + +} + +=pod + +=item $node->clean_node() + +Remove the base directory of the node iff the node has been stopped + +=cut + +sub clean_node +{ + my $self = shift; + + rmtree $self->{_basedir} unless defined $self->{_pid}; } =pod