Commit e663e830 authored by Martin Pitt's avatar Martin Pitt

* t/TestLib.pm: Added check_clean() method to test for empty PostgreSQL

  related directories and processes, and use it in all tests.
parent fc3ce54e
......@@ -17,8 +17,10 @@ postgresql-common (43) unstable; urgency=low
Closes: #353832
* pg_dropcluster: Remove /etc/postgresql/<version> and
/var/lib/postgresql/<version> if empty.
* t/TestLib.pm: Added check_clean() method to test for empty PostgreSQL
related directories and processes, and use it in all tests.
-- Martin Pitt <mpitt@debian.org> Tue, 21 Feb 2006 20:38:41 +0100
-- Martin Pitt <mpitt@debian.org> Tue, 21 Feb 2006 20:48:01 +0100
postgresql-common (42) unstable; urgency=low
......
......@@ -3,13 +3,11 @@
# for this test.
use strict;
use Test::More tests => 3;
use Test::More tests => 7;
use lib 't';
use TestLib;
is (`pg_lsclusters -h`, '', 'No existing clusters');
is ((ps 'postmaster'), '', 'No existing postmaster processes');
is ((ps 'pg_autovacuum'), '', 'No existing pg_autovacuum processes');
check_clean;
# vim: filetype=perl
......@@ -10,7 +10,7 @@ use TestLib;
use lib '/usr/share/postgresql-common';
use PgCommon;
use Test::More tests => 38 * ($#MAJORS+1);
use Test::More tests => 39 * ($#MAJORS+1);
sub check_major {
my $v = $_[0];
......@@ -119,12 +119,7 @@ Bob|1
ok ((system "pg_dropcluster $v main --stop-server") == 0,
'pg_dropcluster removes cluster');
ok_dir "/etc/postgresql/$v", [], "No files in /etc/postgresql/$v left behind";
ok_dir "/var/lib/postgresql/$v", [], "No files in /var/lib/postgresql/$v left behind";
ok_dir '/var/run/postgresql', [], 'No files in /var/run/postgresql left behind';
ok_dir '/var/log/postgresql', [], 'No files in /var/log/postgresql left behind';
is ((ps 'postmaster'), '', 'No postmaster processes left behind');
is ((ps 'pg_autovacuum'), '', 'No pg_autovacuum processes left behind');
check_clean;
}
foreach (@MAJORS) {
......
......@@ -5,7 +5,7 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => 37;
use Test::More tests => 44;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -122,4 +122,6 @@ ok ((system "pg_dropcluster $version main") == 0,
ok_dir $socketdir, [], 'No sockets any more';
rmdir $socketdir or die "rmdir: $!";
check_clean;
# vim: filetype=perl
......@@ -10,7 +10,7 @@ use TestLib;
use lib '/usr/share/postgresql-common';
use PgCommon;
use Test::More tests => 60;
use Test::More tests => 65;
# create cluster
ok ((system "pg_createcluster $MAJORS[0] upgr --start >/dev/null") == 0,
......@@ -116,7 +116,6 @@ testnc|f
is ((system "pg_dropcluster $MAJORS[0] upgr --stop-server"), 0, 'Dropping original cluster');
is ((system "pg_dropcluster $MAJORS[-1] upgr --stop-server"), 0, 'Dropping upgraded cluster');
# Check clusters
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'empty pg_lsclusters output';
check_clean;
# vim: filetype=perl
......@@ -9,7 +9,7 @@ use TestLib;
use lib '/usr/share/postgresql-common';
use PgCommon;
use Test::More tests => 44;
use Test::More tests => 49;
# create a test cluster with given locale, check the locale/encoding, and
# remove it again (unless disabled)
......@@ -60,7 +60,6 @@ check_cluster $MAJORS[-1], 'en_US', 1;
check_cluster $MAJORS[-1], 'en_US', 1, 'UTF-8';
check_cluster $MAJORS[-1], 'en_US.UTF-8', 1;
# Check clusters
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'empty pg_lsclusters output';
check_clean;
# vim: filetype=perl
......@@ -8,7 +8,7 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => 4 + $#MAJORS * 9;
use Test::More tests => 9 + $#MAJORS * 9;
# postgresql.conf configuration file with all available options turned on
my %fullconf;
......@@ -260,7 +260,6 @@ while ($#testversions) {
# remove latest cluster and directory
is ((system "pg_dropcluster $testversions[0] main"), 0, 'Dropping remaining cluster');
# Check clusters
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'empty pg_lsclusters output';
check_clean;
# vim: filetype=perl
......@@ -7,7 +7,7 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => 18;
use Test::More tests => 25;
my $owner = 'nobody';
......@@ -32,4 +32,6 @@ for my $v (@MAJORS[0, -1]) {
is ((ps 'postmaster'), '', 'No postmaster processes left');
}
check_clean;
# vim: filetype=perl
......@@ -9,7 +9,7 @@ use TestLib;
use lib '/usr/share/postgresql-common';
use PgCommon;
use Test::More tests => 55;
use Test::More tests => 60;
# Do test with oldest version
my $v = $MAJORS[0];
......@@ -95,6 +95,7 @@ is ((get_cluster_start_conf $v, 'main'), 'manual',
'get_cluster_start_conf returns manual');
is ((system "pg_dropcluster $v main"), 0,
'dropping cluster');
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'no clusters any more';
check_clean;
# vim: filetype=perl
......@@ -7,7 +7,7 @@ use lib 't';
use TestLib;
use Socket;
use Test::More tests => 38;
use Test::More tests => 43;
# create fake socket at 5433 to verify that this port is skipped
socket (SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "socket: $!";
......@@ -78,6 +78,7 @@ is_program_out 'postgres', 'psql -Atc "show port" template1', 0, "5432\n",
is ((system "pg_dropcluster $MAJORS[-1] new1 --stop-server"), 0, "dropping $new1");
is ((system "pg_dropcluster $MAJORS[-1] new2 --stop-server"), 0, "dropping $new2");
is ((system "pg_dropcluster $MAJORS[0] old --stop-server"), 0, "dropping $old");
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'no clusters any more';
check_clean;
# vim: filetype=perl
......@@ -9,7 +9,7 @@ use Test::More;
our $VERSION = 1.00;
our @ISA = ('Exporter');
our @EXPORT = qw/ps ok_dir exec_as deb_installed is_program_out
like_program_out unlike_program_out pidof pid_env @MAJORS/;
like_program_out unlike_program_out pidof pid_env check_clean @MAJORS/;
use lib '/usr/share/postgresql-common';
use PgCommon qw/get_versions/;
......@@ -140,3 +140,22 @@ sub unlike_program_out {
is $result, $_[2], $_[1];
unlike ($$outref, $_[3], (defined $_[4] ? $_[4] : "correct output of $_[1]"));
}
# Check that all PostgreSQL related directories are empty and no
# postmaster/pg_autovacuum processes are running. Should be called at the end
# of all tests. Does 7 tests.
sub check_clean {
is (`pg_lsclusters -h`, '', 'No existing clusters');
is ((ps 'postmaster'), '', 'No postmaster processes left behind');
is ((ps 'pg_autovacuum'), '', 'No pg_autovacuum processes left behind');
my @check_dirs = ('/etc/postgresql', '/var/lib/postgresql',
'/var/run/postgresql', '/var/log/postgresql');
foreach (@check_dirs) {
if (-d) {
ok_dir $_, [], "No files in $_ left behind";
} else {
pass "Directory $_ does not exist";
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment