[check_postgres] [commit] Shut down test database when done.
check_postgres at bucardo.org
check_postgres at bucardo.org
Thu Apr 23 17:38:47 UTC 2009
Committed by Greg Sabino Mullane <greg at endpoint.com>
Shut down test database when done.
---
t/99_cleanup.t | 21 +++++++++++++++++++++
t/CP_Testing.pm | 18 ++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/t/99_cleanup.t b/t/99_cleanup.t
new file mode 100644
index 0000000..730ed40
--- /dev/null
+++ b/t/99_cleanup.t
@@ -0,0 +1,21 @@
+#!perl
+
+## Cleanup any mess we made
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Test::More tests => 1;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $SQL $t/;
+
+my $cp = CP_Testing->new();
+
+$cp->cleanup();
+
+pass 'Test database has been shut down';
+
+exit;
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index af0e005..11f1e4d 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -28,6 +28,24 @@ sub new {
return bless $self => $class;
}
+sub cleanup {
+
+ my $self = shift;
+ my $dbdir = $self->{dbdir} or die;
+ my $pidfile = "$dbdir/data/postmaster.pid";
+ return if ! -e $pidfile;
+ open my $fh, '<', $pidfile or die qq{Could not open "$pidfile": $!\n};
+ <$fh> =~ /^(\d+)/ or die qq{File "$pidfile" did not start with a number!\n};
+ my $pid = $1;
+ close $fh or die qq{Could not close "$pidfile": $!\n};
+ kill 15 => $pid;
+ sleep 1;
+ if (kill 0 => $pid) {
+ kill 9 => $pid;
+ }
+ return;
+}
+
sub test_database_handle {
## Request for a database handle: create and startup DB as needed
--
1.6.0.5
More information about the Check_postgres
mailing list