I finally nailed the problem from today's earlier post. The comments I received suggested that the table was locking, but how would that happen if I was committing things properly? Well, just in case, I had better write some tests.
$result = $mod->update_admin_message( $update );
ok( $result, 'update_admin_message() should succeed when passed valid data' );
my $new_data = $db->get_admin_message;
is( $new_data->{message},'foobar', '... and should set the message correctly');
Sure enough, the test suite hung when I tried to get the administrative message after setting it. Here's the code that sets it:
sub update_admin_message {
my ( $self, $data ) = @_;
$self->_clear_error;
my ( $fields, $values ) = $self->_format_update_data( $data );
my $sql = "UPDATE adminMessage SET $fields";
$self->_update_database( $sql, $values );
return $self->_success_or_failure;
}
And the _success_or_failure() method:
sub _success_or_failure {
my ( $self, $commit ) = @_;
unless ( $self->{ _error } ) {
$self->{ _dbh }->commit if $commit;
return 1;
} else {
$self->{ _dbh }->rollback;
return;
}
}
Apparently, I forget to pass a true value for the 'commit' parameter. I need to go through now and have all calls to this function explicitly pass a true or false value, rather than defaulting to false via undef. That should prevent this happening again, I hope (though I still don't understand all of the mysterious side-effects that we were experiencing. I fear that I am a bear of little brain).
And for the curious, the beginning of my tests for the mods to the _success_or_failure method.
my $warn;
$SIG{__WARN__} = sub { $warn = join '', @_ };
can_ok( MODULE, '_success_or_failure' );
$data = $mod->_success_or_failure;
ok( ! $data, '... and calling it without and argument should fail' );
ok( $warn, '... and should warn the programmer' );
like( $warn, qr/\QArgument to _success_or_failure() must be defined\E/,
'... with an appropriate error message' );
{
no warnings 'once';
is( $George::Bush, $Big::Idiot, '... but no political statements, please' );
}
If you can't have a little fun at work ... :)