Shut down test database when done.
authorGreg Sabino Mullane <greg@endpoint.com>
Thu, 23 Apr 2009 17:34:26 +0000 (13:34 -0400)
committerGreg Sabino Mullane <greg@endpoint.com>
Thu, 23 Apr 2009 17:34:26 +0000 (13:34 -0400)
t/99_cleanup.t [new file with mode: 0644]
t/CP_Testing.pm

diff --git a/t/99_cleanup.t b/t/99_cleanup.t
new file mode 100644 (file)
index 0000000..730ed40
--- /dev/null
@@ -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;
index af0e005a070b5157f140aa4054d91833306eb645..11f1e4dd6d5c4177e52aa84f8c4bbeee1346b028 100644 (file)
@@ -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