Cxn & pt-osc: Guard the cleanup tasks.

Does this twofold: By adding a __DIE__ hook to make sure they are
called, and by checking that the dbh is an actual database handle.
This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-06-05 16:24:32 -03:00
parent c4a8a67204
commit e57b67f10e
2 changed files with 25 additions and 12 deletions

View File

@@ -35,13 +35,15 @@ package Cxn;
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
# Hostnames make testing less accurate. Tests need to see
# that such-and-such happened on specific slave hosts, but
# the sandbox servers are all on one host so all slaves have
# the same hostname.
use constant PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0;
use Scalar::Util qw(blessed);
use constant {
PTDEBUG => $ENV{PTDEBUG} || 0,
# Hostnames make testing less accurate. Tests need to see
# that such-and-such happened on specific slave hosts, but
# the sandbox servers are all on one host so all slaves have
# the same hostname.
PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0,
};
# Sub: new
#
@@ -193,7 +195,9 @@ sub name {
sub DESTROY {
my ($self) = @_;
if ( $self->{dbh} && ref($self->{dbh}) ) {
if ( $self->{dbh}
&& blessed($self->{dbh})
&& $self->{dbh}->can("disconnect") ) {
PTDEBUG && _d('Disconnecting dbh', $self->{dbh}, $self->{name});
$self->{dbh}->disconnect();
}