X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Freplicated.t;h=c8d469fd6e4813ec5bce014218964b70bfc1403a;hb=ghpr%2Fclosed%2Finspiring_eef9b484;hp=56d141afe2be9ac78f7c3d356f3abcc660d58d39;hpb=7672675a2bafc1ddc0bd4237c01c36acfdcda71c;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/storage/replicated.t b/t/storage/replicated.t index 56d141a..c8d469f 100644 --- a/t/storage/replicated.t +++ b/t/storage/replicated.t @@ -3,12 +3,22 @@ use warnings; use Test::More; +use lib qw(t/lib); +use DBICTest; + BEGIN { require DBIx::Class; plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_replicated') unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_replicated'); } + +if (DBICTest::RunMode->is_smoker) { + my $mver = Moose->VERSION; + plan skip_all => "A trial version $mver of Moose detected known to break replication - skipping test known to fail" + if ($mver >= 1.99 and $mver <= 1.9902); +} + use Test::Moose; use Test::Exception; use List::Util 'first'; @@ -19,9 +29,6 @@ use Moose(); use MooseX::Types(); note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION"; -use lib qw(t/lib); -use DBICTest; - my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) ); use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool'; @@ -72,15 +79,8 @@ TESTSCHEMACLASSES: { ## Get the Schema and set the replication storage type sub init_schema { - # current SQLT SQLite producer does not handle DROP TABLE IF EXISTS, trap warnings here - local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s }; - - my ($class, $schema_method) = @_; - - my $method = "get_schema_$schema_method"; - my $schema = $class->$method; - - return $schema; + #my ($class, $schema_getter) = @_; + shift->${\ ( 'get_schema_' . shift ) }; } sub get_schema_by_storage_type { @@ -603,7 +603,7 @@ $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0); "got last query from a master: $debug{dsn}"; like $fallback_warning, qr/falling back to master/ - => 'emits falling back to master warning'; + => 'emits falling back to master debug'; $replicated->schema->storage->debugfh($oldfh); } @@ -620,11 +620,23 @@ $replicated->schema->storage->pool->validate_replicants; $replicated->schema->storage->debugobj->silence(0); -ok $replicated->schema->resultset('Artist')->find(2) - => 'Returned to replicates'; +{ + ## catch the fallback to master warning + open my $debugfh, '>', \my $return_warning; + my $oldfh = $replicated->schema->storage->debugfh; + $replicated->schema->storage->debugfh($debugfh); + + ok $replicated->schema->resultset('Artist')->find(2) + => 'Return to replicants'; + + is $debug{storage_type}, 'REPLICANT', + "got last query from a replicant: $debug{dsn}"; -is $debug{storage_type}, 'REPLICANT', - "got last query from a replicant: $debug{dsn}"; + like $return_warning, qr/Moved back to slave/ + => 'emits returning to slave debug'; + + $replicated->schema->storage->debugfh($oldfh); +} ## Getting slave status tests