[Check_postgres-commit] [commit] Use "dbnum" for multiple databases, and make sure we cleanup symlinks as well.

check_postgres at bucardo.org check_postgres at bucardo.org
Fri Jun 12 22:03:04 UTC 2009


Committed by Greg Sabino Mullane <greg at endpoint.com>

Use "dbnum" for multiple databases, and make sure we cleanup symlinks as well.

---
 t/02_same_schema.t |    3 +--
 t/CP_Testing.pm    |   32 +++++++++++++++++++++-----------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/t/02_same_schema.t b/t/02_same_schema.t
index be523d3..4eea20c 100644
--- a/t/02_same_schema.t
+++ b/t/02_same_schema.t
@@ -13,8 +13,7 @@ use CP_Testing;
 use vars qw/$dbh1 $dbh2 $SQL $t $stdargs/;
 
 my $cp1 = CP_Testing->new({ default_action => 'same_schema' });
-my $cp2 = CP_Testing->new({ default_action => 'same_schema',
-                            dbdir => $cp1->{dbdir} . '2' });
+my $cp2 = CP_Testing->new({ default_action => 'same_schema', dbnum => 2});
 
 $dbh1 = $cp1->test_database_handle();
 $dbh1->{AutoCommit} = 1;
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index 5638cb1..a9cafd5 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -12,7 +12,6 @@ use Cwd;
 
 our $DEBUG = 0;
 our $MAX_HOST_PATH = 60;
-our $next_socket_mod = 1;
 
 use vars qw/$com $info $count $SQL $sth/;
 
@@ -29,6 +28,9 @@ sub new {
 	if (exists $arg->{default_action}) {
 		$self->{action} = $arg->{default_action};
 	}
+	if (exists $arg->{dbnum} and $arg->{dbnum}) {
+		$self->{dbdir} .= $arg->{dbnum};
+	}
 	return bless $self => $class;
 }
 
@@ -38,15 +40,20 @@ sub cleanup {
 	my $dbdir = $self->{dbdir} or die;
 	for my $dirnum ('', '2', '3', '4', '5') {
 		my $pidfile = "$dbdir$dirnum/data space/postmaster.pid";
-		next 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;
+		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;
+			}
+		}
+		my $symlink = "/tmp/cptesting_socket$dirnum";
+		if (-l $symlink) {
+			unlink $symlink;
 		}
 	}
 
@@ -244,7 +251,10 @@ sub test_database_handle {
 
 	## Workaround for bug where psql -h /some/long/path fails
 	if (length($dbhost) > $MAX_HOST_PATH) {
-		my $newname = '/tmp/cptesting_socket' . ($next_socket_mod++);
+		my $newname = '/tmp/cptesting_socket';
+		if ($self->{dbdir} =~ /(\d+)$/) {
+			$newname .= $1;
+		}
 		if (! -e $newname) {
 			warn "Creating new symlink socket at $newname\n";
 			(my $oldname = $dbhost) =~ s/\\//g;
-- 
1.6.2.2



More information about the Check_postgres-commit mailing list