X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F93storage_replication.t;h=b85da4a6e1b5f6b56f685b4a60914bd55f749589;hb=49aa0bc52384f75cc6a8efec7c8caf4ab1f4f25b;hp=f96d49bc4c924225f3b969e1c6f1d6884b82bdd8;hpb=dcdf7b2cd485cc015ddbfd816f6735be075c3386;p=dbsrgits%2FDBIx-Class.git diff --git a/t/93storage_replication.t b/t/93storage_replication.t index f96d49b..b85da4a 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -6,12 +6,13 @@ use Test::Exception; use DBICTest; use List::Util 'first'; use Scalar::Util 'reftype'; +use IO::Handle; BEGIN { eval "use DBIx::Class::Storage::DBI::Replicated; use Test::Moose"; plan $@ ? ( skip_all => "Deps not installed: $@" ) - : ( tests => 88 ); + : ( tests => 90 ); } use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool'; @@ -80,6 +81,7 @@ TESTSCHEMACLASSES: { balancer_type=>'::Random', balancer_args=>{ auto_validate_every=>100, + master_read_weight => 1 }, } }, @@ -96,6 +98,7 @@ TESTSCHEMACLASSES: { balancer_type=>'::Random', balancer_args=> { auto_validate_every=>100, + master_read_weight => 1 }, deploy_args=>{ add_drop_table => 1, @@ -356,6 +359,28 @@ isa_ok $artist1 is $artist1->name, 'Ozric Tentacles' => 'Found expected name for first result'; +## Check that master_read_weight is honored +{ + no warnings 'once'; + + # turn off redefined warning + local $SIG{__WARN__} = sub {}; + + local + *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number = + sub { 999 }; + + $replicated->schema->storage->balancer->increment_storage; + + is $replicated->schema->storage->balancer->current_replicant, + $replicated->schema->storage->master + => 'master_read_weight is honored'; + + ## turn it off for the duration of the test + $replicated->schema->storage->balancer->master_read_weight(0); + $replicated->schema->storage->balancer->increment_storage; +} + ## Add some new rows that only the master will have This is because ## we overload any type of write operation so that is must hit the master ## database. @@ -445,13 +470,20 @@ ok $replicated->schema->resultset('Artist')->find(2) $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0); $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0); -## Silence warning about falling back to master. -$replicated->schema->storage->debugobj->silence(1); - -ok $replicated->schema->resultset('Artist')->find(2) - => 'Fallback to master'; +{ + ## catch the fallback to master warning + open my $debugfh, '>', \my $fallback_warning; + my $oldfh = $replicated->schema->storage->debugfh; + $replicated->schema->storage->debugfh($debugfh); -$replicated->schema->storage->debugobj->silence(0); + ok $replicated->schema->resultset('Artist')->find(2) + => 'Fallback to master'; + + like $fallback_warning, qr/falling back to master/ + => 'emits falling back to master warning'; + + $replicated->schema->storage->debugfh($oldfh); +} $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1); $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1); @@ -684,3 +716,5 @@ ok $replicated->schema->resultset('Artist')->find(1) ## Delete the old database files $replicated->cleanup; + +# vim: sw=4 sts=4 :