From: Greg Sabino Mullane Date: Thu, 23 Apr 2009 17:34:26 +0000 (-0400) Subject: Shut down test database when done. X-Git-Tag: 2.9.0~97 X-Git-Url: http://git.postgresql.org/gitweb/static/main.js?a=commitdiff_plain;h=b4cfc83022f50f31c3da483968f5632b868ce8af;p=check_postgres.git Shut down test database when done. --- 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