From: Daniel Gustafsson =0A= Date: Tue, 25 Apr 2017 15:59:48 +0200=0A= Subject: [PATCH] Support retaining datadir on successful TAP tests=0A= =0A= This moves the datadirs from using tempdirs with randomness in=0A= the directory name to a static name to make it easier to clean=0A= up as well as debug. The datadir will be retained in case the=0A= the tests fail or the testcode dies/exits with failure, and is=0A= automatically removed on make check. In case PG_TESTS_NOCLEAN=0A= is defined the datadirs will be retained regardless of test or=0A= exit status.=0A= =0A= Additionally, a new make target 'check-clean' is added to the=0A= directories containing TAP tests to allow for cleaning retained=0A= datadirs.=0A= ---=0A= src/Makefile.global.in | 11 ++++++++--=0A= src/bin/initdb/Makefile | 3 +++=0A= src/bin/pg_basebackup/Makefile | 3 +++=0A= src/bin/pg_config/Makefile | 3 +++=0A= src/bin/pg_controldata/Makefile | 3 +++=0A= src/bin/pg_ctl/Makefile | 3 +++=0A= src/bin/pg_dump/Makefile | 3 +++=0A= src/bin/pg_rewind/Makefile | 3 +++=0A= src/bin/pgbench/Makefile | 3 +++=0A= src/bin/scripts/Makefile | 3 +++=0A= src/test/perl/PostgresNode.pm | 47 +++++++++++++++++++++++++++++++++++++= +---=0A= 11 files changed, 80 insertions(+), 5 deletions(-)=0A= =0A= diff --git a/src/Makefile.global.in b/src/Makefile.global.in=0A= index b83f09f..579b40a 100644=0A= --- a/src/Makefile.global.in=0A= +++ b/src/Makefile.global.in=0A= @@ -359,18 +359,25 @@ endef=0A= ifeq ($(enable_tap_tests),yes)=0A= =20=0A= define prove_installcheck=0A= -rm -rf $(CURDIR)/tmp_check/log=0A= +rm -rf $(CURDIR)/tmp_check/=0A= +mkir -p $(CURDIR)/tmp_check/=0A= cd $(srcdir) && TESTDIR=3D'$(CURDIR)' PATH=3D"$(bindir):$$PATH" PGPORT=3D'= 6$(DEF_PGPORT)' top_builddir=3D'$(CURDIR)/$(top_builddir)' PG_REGRESS=3D'$(= CURDIR)/$(top_builddir)/src/test/regress/pg_regress' $(PROVE) $(PG_PROVE_FL= AGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)=0A= endef=0A= =20=0A= define prove_check=0A= -rm -rf $(CURDIR)/tmp_check/log=0A= +rm -rf $(CURDIR)/tmp_check/=0A= +mkdir -p $(CURDIR)/tmp_check/=0A= cd $(srcdir) && TESTDIR=3D'$(CURDIR)' $(with_temp_install) PGPORT=3D'6$(DE= F_PGPORT)' PG_REGRESS=3D'$(CURDIR)/$(top_builddir)/src/test/regress/pg_regr= ess' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_= TESTS),t/*.pl)=0A= endef=0A= =20=0A= +define prove_clean=0A= +rm -rf $(CURDIR)/tmp_check/t_*_data=0A= +endef=0A= +=0A= else=0A= prove_installcheck =3D @echo "TAP tests not enabled"=0A= prove_check =3D $(prove_installcheck)=0A= +prove_clean =3D $(prove_installcheck)=0A= endif=0A= =20=0A= # Installation.=0A= diff --git a/src/bin/initdb/Makefile b/src/bin/initdb/Makefile=0A= index eaed050..f73f9a3 100644=0A= --- a/src/bin/initdb/Makefile=0A= +++ b/src/bin/initdb/Makefile=0A= @@ -66,3 +66,6 @@ check:=0A= =20=0A= installcheck:=0A= $(prove_installcheck)=0A= +=0A= +check-clean:=0A= + $(prove_clean)=0A= diff --git a/src/bin/pg_basebackup/Makefile b/src/bin/pg_basebackup/Makefil= e=0A= index f0c3be8..5fe5b4f 100644=0A= --- a/src/bin/pg_basebackup/Makefile=0A= +++ b/src/bin/pg_basebackup/Makefile=0A= @@ -58,3 +58,6 @@ check:=0A= =20=0A= installcheck:=0A= $(prove_installcheck)=0A= +=0A= +check-clean:=0A= + $(prove_clean)=0A= diff --git a/src/bin/pg_config/Makefile b/src/bin/pg_config/Makefile=0A= index c410087..8d7e97a 100644=0A= --- a/src/bin/pg_config/Makefile=0A= +++ b/src/bin/pg_config/Makefile=0A= @@ -40,3 +40,6 @@ check:=0A= =20=0A= installcheck:=0A= $(prove_installcheck)=0A= +=0A= +check-clean:=0A= + $(prove_clean)=0A= diff --git a/src/bin/pg_controldata/Makefile b/src/bin/pg_controldata/Makef= ile=0A= index fd87daa..ce93c84 100644=0A= --- a/src/bin/pg_controldata/Makefile=0A= +++ b/src/bin/pg_controldata/Makefile=0A= @@ -40,3 +40,6 @@ check:=0A= =20=0A= installcheck:=0A= $(prove_installcheck)=0A= +=0A= +check-clean:=0A= + $(prove_clean)=0A= diff --git a/src/bin/pg_ctl/Makefile b/src/bin/pg_ctl/Makefile=0A= index f5ec088..83bb153 100644=0A= --- a/src/bin/pg_ctl/Makefile=0A= +++ b/src/bin/pg_ctl/Makefile=0A= @@ -43,3 +43,6 @@ check:=0A= =20=0A= installcheck:=0A= $(prove_installcheck)=0A= +=0A= +check-clean:=0A= + $(prove_clean)=0A= diff --git a/src/bin/pg_dump/Makefile b/src/bin/pg_dump/Makefile=0A= index b58636e..3f347ed 100644=0A= --- a/src/bin/pg_dump/Makefile=0A= +++ b/src/bin/pg_dump/Makefile=0A= @@ -48,6 +48,9 @@ check:=0A= installcheck:=0A= $(prove_installcheck)=0A= =20=0A= +check-clean:=0A= + $(prove_clean)=0A= +=0A= uninstall:=0A= rm -f $(addprefix '$(DESTDIR)$(bindir)'/, pg_dump$(X) pg_restore$(X) pg_d= umpall$(X))=0A= =20=0A= diff --git a/src/bin/pg_rewind/Makefile b/src/bin/pg_rewind/Makefile=0A= index 828ae01..0074648 100644=0A= --- a/src/bin/pg_rewind/Makefile=0A= +++ b/src/bin/pg_rewind/Makefile=0A= @@ -52,3 +52,6 @@ check:=0A= =20=0A= installcheck:=0A= $(prove_installcheck)=0A= +=0A= +check-clean:=0A= + $(prove_clean)=0A= diff --git a/src/bin/pgbench/Makefile b/src/bin/pgbench/Makefile=0A= index 1503d00..af72189 100644=0A= --- a/src/bin/pgbench/Makefile=0A= +++ b/src/bin/pgbench/Makefile=0A= @@ -48,3 +48,6 @@ check:=0A= =20=0A= installcheck:=0A= $(prove_installcheck)=0A= +=0A= +check-clean:=0A= + $(prove_clean)=0A= diff --git a/src/bin/scripts/Makefile b/src/bin/scripts/Makefile=0A= index 45ac492..a0268dd 100644=0A= --- a/src/bin/scripts/Makefile=0A= +++ b/src/bin/scripts/Makefile=0A= @@ -59,5 +59,8 @@ clean distclean maintainer-clean:=0A= check:=0A= $(prove_check)=0A= =20=0A= +check-clean:=0A= + $(prove_clean)=0A= +=0A= installcheck:=0A= $(prove_installcheck)=0A= diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm= =0A= index 51cbec8..2eed791 100644=0A= --- a/src/test/perl/PostgresNode.pm=0A= +++ b/src/test/perl/PostgresNode.pm=0A= @@ -86,6 +86,7 @@ use Config;=0A= use Cwd;=0A= use Exporter 'import';=0A= use File::Basename;=0A= +use File::Path;=0A= use File::Spec;=0A= use File::Temp ();=0A= use IPC::Run;=0A= @@ -99,7 +100,7 @@ our @EXPORT =3D qw(=0A= get_new_node=0A= );=0A= =20=0A= -our ($test_localhost, $test_pghost, $last_port_assigned, @all_nodes);=0A= +our ($test_localhost, $test_pghost, $last_port_assigned, @all_nodes, $died= );=0A= =20=0A= # Windows path to virtual file system root=0A= =20=0A= @@ -148,11 +149,13 @@ sub new=0A= my $self =3D {=0A= _port =3D> $pgport,=0A= _host =3D> $pghost,=0A= - _basedir =3D> TestLib::tempdir("data_" . $name),=0A= + _basedir =3D> "$TestLib::tmp_check/t_${testname}_${name}_data",=0A= _name =3D> $name,=0A= _logfile =3D> "$TestLib::log_path/${testname}_${name}.log" };=0A= =20=0A= bless $self, $class;=0A= + BAIL_OUT("unable to create datadir \"$self->{_basedir}\"")=0A= + unless mkdir $self->{_basedir};=0A= $self->dump_info;=0A= =20=0A= return $self;=0A= @@ -921,9 +924,24 @@ sub get_new_node=0A= return $node;=0A= }=0A= =20=0A= +# Retain the errno on die() if set, else assume a generic errno of 1. This= =0A= +# will instruct the END handler on how to handle artifacts left behind fro= m=0A= +# tests=0A= +$SIG{__DIE__} =3D sub=0A= +{=0A= + if ($!)=0A= + {=0A= + $died =3D $!;=0A= + }=0A= + else=0A= + {=0A= + $died =3D 1;=0A= + }=0A= +};=0A= +=0A= # Automatically shut down any still-running nodes when the test script exi= ts.=0A= # Note that this just stops the postmasters (in the same order the nodes w= ere=0A= -# created in). Temporary PGDATA directories are deleted, in an unspecifie= d=0A= +# created in). Any temporary directories are deleted, in an unspecified= =0A= # order, later when the File::Temp objects are destroyed.=0A= END=0A= {=0A= @@ -934,6 +952,13 @@ END=0A= foreach my $node (@all_nodes)=0A= {=0A= $node->teardown_node;=0A= +=0A= + # skip clean if we are requested to retain the basedir=0A= + next if (defined $ENV{'PG_TESTS_NOCLEAN'});=0A= +=0A= + # clean basedir on clean test invocation=0A= + $node->clean_node=0A= + unless (!TestLib::all_tests_passing() || defined $died || $exit_code);= =0A= }=0A= =20=0A= $? =3D $exit_code;=0A= @@ -952,6 +977,22 @@ sub teardown_node=0A= my $self =3D shift;=0A= =20=0A= $self->stop('immediate');=0A= +=0A= +}=0A= +=0A= +=3Dpod=0A= +=0A= +=3Ditem $node->clean_node()=0A= +=0A= +Remove the base directory of the node iff the node has been stopped=0A= +=0A= +=3Dcut=0A= +=0A= +sub clean_node=0A= +{=0A= + my $self =3D shift;=0A= +=0A= + rmtree $self->{_basedir} unless defined $self->{_pid};=0A= }=0A= =20=0A= =3Dpod=0A= --=20=0A= 2.6.4 (Apple Git-63)=0A= =0A= --Apple-Mail=_679018E4-CAE2-4C2D-B267-D9188C30A1D8 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --Apple-Mail=_679018E4-CAE2-4C2D-B267-D9188C30A1D8--