X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F93storage_replication.t;h=a2a130daa9bdcd29a90a7cb8475473cf0a28766f;hb=2ce6e9a68d68fa86e3b28df61496e85c996b2c1a;hp=77657677dffe68c54a21d1b1297e4e83762b5f50;hpb=c4d3fae2d68b67050e6f4a04031608506e9a18e8;p=dbsrgits%2FDBIx-Class.git diff --git a/t/93storage_replication.t b/t/93storage_replication.t index 7765767..a2a130d 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -9,7 +9,7 @@ BEGIN { eval "use Moose; use Test::Moose"; plan $@ ? ( skip_all => 'needs Moose for testing' ) - : ( tests => 57 ); + : ( tests => 77 ); } use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool'; @@ -243,6 +243,8 @@ $replicated ## Make sure all the slaves have the table definitions $replicated->replicate; +$replicated->schema->storage->replicants->{$replicant_names[0]}->active(1); +$replicated->schema->storage->replicants->{$replicant_names[1]}->active(1); ## Make sure we can read the data. @@ -455,31 +457,118 @@ ok my $unreliably = sub { } => 'created coderef properly'; throws_ok {$replicated->schema->storage->execute_reliably($unreliably)} - qr/coderef returned an error: Can't find source for ArtistXX/ + qr/Can't find source for ArtistXX/ => 'Bad coderef throws proper error'; +## Make sure replication came back + +ok $replicated->schema->resultset('Artist')->find(3) + => 'replicant reactivated'; + ## make sure transactions are set to execute_reliably ok my $transaction = sub { + my $id = shift @_; + $replicated ->schema ->populate('Artist', [ [ qw/artistid name/ ], - [ 666, "Children of the Grave"], + [ $id, "Children of the Grave"], ]); - ok my $result = $replicated->schema->resultset('Artist')->find(666); + ok my $result = $replicated->schema->resultset('Artist')->find($id) + => 'Found expected artist'; + + ok my $more = $replicated->schema->resultset('Artist')->find(1) + => 'Found expected artist again'; + + return ($result, $more); -}; +} => 'Created a coderef properly'; + +## Test the transaction with multi return +{ + ok my @return = $replicated->schema->txn_do($transaction, 666) + => 'did transaction'; + + is $return[0]->id, 666 + => 'first returned value is correct'; + + is $return[1]->id, 1 + => 'second returned value is correct'; +} + +## Test that asking for single return works +{ + ok my $return = $replicated->schema->txn_do($transaction, 777) + => 'did transaction'; + + is $return->id, 777 + => 'first returned value is correct'; +} -$replicated->schema->txn_do($transaction); +## Test transaction returning a single value + +{ + ok my $result = $replicated->schema->txn_do(sub { + ok my $more = $replicated->schema->resultset('Artist')->find(1) + => 'found inside a transaction'; + return $more; + }) => 'successfully processed transaction'; + + is $result->id, 1 + => 'Got expected single result from transaction'; +} ## Make sure replication came back -ok $replicated->schema->resultset('Artist')->find(5) +ok $replicated->schema->resultset('Artist')->find(1) => 'replicant reactivated'; - + +## Test Discard changes + +{ + ok my $artist = $replicated->schema->resultset('Artist')->find(2) + => 'got an artist to test discard changes'; + + ok $artist->discard_changes + => 'properly discard changes'; +} + +## Test some edge cases, like trying to do a transaction inside a transaction, etc + +{ + ok my $result = $replicated->schema->txn_do(sub { + return $replicated->schema->txn_do(sub { + ok my $more = $replicated->schema->resultset('Artist')->find(1) + => 'found inside a transaction inside a transaction'; + return $more; + }); + }) => 'successfully processed transaction'; + + is $result->id, 1 + => 'Got expected single result from transaction'; +} + +{ + ok my $result = $replicated->schema->txn_do(sub { + return $replicated->schema->storage->execute_reliably(sub { + return $replicated->schema->txn_do(sub { + return $replicated->schema->storage->execute_reliably(sub { + ok my $more = $replicated->schema->resultset('Artist')->find(1) + => 'found inside crazy deep transactions and execute_reliably'; + return $more; + }); + }); + }); + }) => 'successfully processed transaction'; + + is $result->id, 1 + => 'Got expected single result from transaction'; +} + ## Delete the old database files $replicated->cleanup;