X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=blobdiff_plain;f=t%2F93storage_replication.t;h=77657677dffe68c54a21d1b1297e4e83762b5f50;hp=7617af36398d17fbd8168d78763296eff4e11a99;hb=c4d3fae2d68b67050e6f4a04031608506e9a18e8;hpb=9c0df5f32b68e23c670c89ce6cdbff60b4bd0ed0 diff --git a/t/93storage_replication.t b/t/93storage_replication.t index 7617af3..7765767 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -2,13 +2,14 @@ use strict; use warnings; use lib qw(t/lib); use Test::More; +use Test::Exception; use DBICTest; BEGIN { eval "use Moose; use Test::Moose"; plan $@ ? ( skip_all => 'needs Moose for testing' ) - : ( tests => 50 ); + : ( tests => 57 ); } use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool'; @@ -433,6 +434,52 @@ SKIP: { => "both replicants reactivated"; } +## Test the reliably callback + +ok my $reliably = sub { + + ok $replicated->schema->resultset('Artist')->find(5) + => 'replicant reactivated'; + +} => 'created coderef properly'; + +$replicated->schema->storage->execute_reliably($reliably); + +## Try something with an error + +ok my $unreliably = sub { + + ok $replicated->schema->resultset('ArtistXX')->find(5) + => 'replicant reactivated'; + +} => 'created coderef properly'; + +throws_ok {$replicated->schema->storage->execute_reliably($unreliably)} + qr/coderef returned an error: Can't find source for ArtistXX/ + => 'Bad coderef throws proper error'; + +## make sure transactions are set to execute_reliably + +ok my $transaction = sub { + + $replicated + ->schema + ->populate('Artist', [ + [ qw/artistid name/ ], + [ 666, "Children of the Grave"], + ]); + + ok my $result = $replicated->schema->resultset('Artist')->find(666); + +}; + +$replicated->schema->txn_do($transaction); + +## Make sure replication came back + +ok $replicated->schema->resultset('Artist')->find(5) + => 'replicant reactivated'; + ## Delete the old database files $replicated->cleanup;