ifeq ($(enable_tap_tests),yes)
define prove_installcheck
-rm -rf $(CURDIR)/tmp_check/log
+rm -rf '$(CURDIR)'/tmp_check
+$(MKDIR_P) '$(CURDIR)'/tmp_check
cd $(srcdir) && TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' 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_check
-rm -rf $(CURDIR)/tmp_check/log
+rm -rf '$(CURDIR)'/tmp_check
+$(MKDIR_P) '$(CURDIR)'/tmp_check
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
sub setup_cluster
{
+ my $extra_name = shift;
# Initialize master, data checksums are mandatory
- $node_master = get_new_node('master');
+ $node_master = get_new_node('master' . ($extra_name ? "_${extra_name}" : ''));
$node_master->init(allows_streaming => 1);
}
sub create_standby
{
- $node_standby = get_new_node('standby');
+ my $extra_name = shift;
+
+ $node_standby = get_new_node('standby' . ($extra_name ? "_${extra_name}" : ''));
$node_master->backup('my_backup');
$node_standby->init_from_backup($node_master, 'my_backup');
my $connstr_master = $node_master->connstr();
{
my $test_mode = shift;
- RewindTest::setup_cluster();
+ RewindTest::setup_cluster($test_mode);
RewindTest::start_master();
# Create a test table and insert a row in master.
master_psql("CHECKPOINT");
- RewindTest::create_standby();
+ RewindTest::create_standby($test_mode);
# Insert additional data on master that will be replicated to standby
master_psql("INSERT INTO tbl1 values ('in master, before promotion')");
{
my $test_mode = shift;
- RewindTest::setup_cluster();
+ RewindTest::setup_cluster($test_mode);
RewindTest::start_master();
# Create a database in master.
master_psql('CREATE DATABASE inmaster');
- RewindTest::create_standby();
+ RewindTest::create_standby($test_mode);
# Create another database, the creation is replicated to the standby
master_psql('CREATE DATABASE beforepromotion');
{
my $test_mode = shift;
- RewindTest::setup_cluster();
+ RewindTest::setup_cluster($test_mode);
RewindTest::start_master();
my $test_master_datadir = $node_master->data_dir;
append_to_file "$test_master_datadir/tst_both_dir/both_subdir/both_file3",
"in both3";
- RewindTest::create_standby();
+ RewindTest::create_standby($test_mode);
# Create different subdirs and files in master and standby
my $test_standby_datadir = $node_standby->data_dir;
my $master_xlogdir = "${TestLib::tmp_check}/xlog_master";
rmtree($master_xlogdir);
- RewindTest::setup_cluster();
+ RewindTest::setup_cluster($test_mode);
my $test_master_datadir = $node_master->data_dir;
master_psql("CHECKPOINT");
- RewindTest::create_standby();
+ RewindTest::create_standby($test_mode);
# Insert additional data on master that will be replicated to standby
master_psql("INSERT INTO tbl1 values ('in master, before promotion')");
use Cwd;
use Exporter 'import';
use File::Basename;
+use File::Path qw(rmtree);
use File::Spec;
use File::Temp ();
use IPC::Run;
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
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;
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
{
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;
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