X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F93storage_replication.t;h=419f2fe729c6129f633f60d9af6f4dc6aeba55e2;hb=5c1d82d2851b1a019720b111321a3a05ad554fc0;hp=77657677dffe68c54a21d1b1297e4e83762b5f50;hpb=c4d3fae2d68b67050e6f4a04031608506e9a18e8;p=dbsrgits%2FDBIx-Class.git diff --git a/t/93storage_replication.t b/t/93storage_replication.t index 7765767..419f2fe 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 => 71 ); } 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,30 +457,81 @@ 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); + ok my $more = $replicated->schema->resultset('Artist')->find(1); + + return ($result, $more); }; -$replicated->schema->txn_do($transaction); +## 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'; +} + +## Test transaction returning a single value + +{ + ok my $result = $replicated->schema->txn_do(sub { + ok my $more = $replicated->schema->resultset('Artist')->find(1); + 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'; +} ## Delete the old database files $replicated->cleanup;