X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Ferror.t;h=e01da704764dc93d22a4a197a710da65e9d15c53;hb=534521dac62f6ab58e83a42d4e8e3cb586db464b;hp=6c9b15cd992cbcd433cb37b1377ce62f1d142731;hpb=a4f3b65c5eeb1c1fbe41128dc97b88e1b7f506e5;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/error.t b/t/storage/error.t index 6c9b15c..e01da70 100644 --- a/t/storage/error.t +++ b/t/storage/error.t @@ -8,6 +8,61 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; +for my $conn_args ( + [ on_connect_do => "_NOPE_" ], + [ on_connect_call => sub { shift->_dbh->do("_NOPE_") } ], + [ on_connect_call => "_NOPE_" ], +) { + for my $method (qw( ensure_connected _server_info _get_server_version _get_dbh )) { + + my $s = DBICTest->init_schema( + no_deploy => 1, + on_disconnect_call => sub { fail 'Disconnector should not be invoked' }, + @$conn_args + ); + + my $storage = $s->storage; + $storage = $storage->master if $ENV{DBICTEST_VIA_REPLICATED}; + + ok( ! $storage->connected, 'Starting unconnected' ); + + my $desc = "calling $method with broken on_connect action @{[ explain $conn_args ]}"; + + throws_ok { $storage->$method } + qr/ _NOPE_ \b/x, + "Throwing correctly when $desc"; + + ok( ! $storage->connected, "Still not connected after $desc" ); + + # this checks that the on_disconect_call FAIL won't trigger + $storage->disconnect; + } +} + +for my $conn_args ( + [ on_disconnect_do => "_NOPE_" ], + [ on_disconnect_call => sub { shift->_dbh->do("_NOPE_") } ], + [ on_disconnect_call => "_NOPE_" ], +) { + my $s = DBICTest->init_schema( no_deploy => 1, @$conn_args ); + + my $storage = $s->storage; + $storage = $storage->master if $ENV{DBICTEST_VIA_REPLICATED}; + + my $desc = "broken on_disconnect action @{[ explain $conn_args ]}"; + + # connect + ping + my $dbh = $storage->dbh; + + ok ($dbh->FETCH('Active'), 'Freshly connected DBI handle is healthy'); + + warnings_exist { eval { $storage->disconnect } } [ + qr/\QDisconnect action failed\E .+ _NOPE_ \b/x + ], "Found warning of failed $desc"; + + ok (! $dbh->FETCH('Active'), "Actual DBI disconnect was not prevented by $desc" ); +} + my $schema = DBICTest->init_schema; warnings_are ( sub {