summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Sabino Mullane2009-04-23 17:34:26 +0000
committerGreg Sabino Mullane2009-04-23 17:34:26 +0000
commitb4cfc83022f50f31c3da483968f5632b868ce8af (patch)
tree2c4b2a991cc64bb23b0f460a6514c305762eb7a9
parentb1773c0b220b71ac486dfd4bfb2d7a95f623db32 (diff)
Shut down test database when done.
-rw-r--r--t/99_cleanup.t21
-rw-r--r--t/CP_Testing.pm18
2 files changed, 39 insertions, 0 deletions
diff --git a/t/99_cleanup.t b/t/99_cleanup.t
new file mode 100644
index 000000000..730ed4005
--- /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 af0e005a0..11f1e4dd6 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