X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Freplicated.t;h=82c809d306598775281f629e894fb235d107dcce;hb=5c505cafa292b25dbbfb0df53ac30e73069834a2;hp=dc77f0b9f08c1fcb1710791f94fa816a6168d4a0;hpb=e4ee58613571bad55096510fa24608ded39f4e63;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/replicated.t b/t/storage/replicated.t index dc77f0b..82c809d 100644 --- a/t/storage/replicated.t +++ b/t/storage/replicated.t @@ -1,21 +1,19 @@ +use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_replicated'; + use strict; use warnings; use Test::More; - -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'); -} - +use DBIx::Class::_Util 'modver_gt_or_eq_and_lt'; use lib qw(t/lib); use DBICTest; -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); +BEGIN { + plan skip_all => "A trial version of Moose detected known to break replication - skipping test known to fail" if ( + DBICTest::RunMode->is_smoker + and + modver_gt_or_eq_and_lt( 'Moose', '1.99', '1.9903' ) + ) } use Test::Moose; @@ -23,17 +21,32 @@ use Test::Exception; use List::Util 'first'; use Scalar::Util 'reftype'; use File::Spec; -use IO::Handle; use Moose(); use MooseX::Types(); note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION"; my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) ); -use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool'; -use_ok 'DBIx::Class::Storage::DBI::Replicated::Balancer'; -use_ok 'DBIx::Class::Storage::DBI::Replicated::Replicant'; -use_ok 'DBIx::Class::Storage::DBI::Replicated'; +## Add a connect_info option to test option merging. +use DBIx::Class::Storage::DBI::Replicated; +{ + package DBIx::Class::Storage::DBI::Replicated; + + use Moose; + + __PACKAGE__->meta->make_mutable; + + around connect_info => sub { + my ($next, $self, $info) = @_; + $info->[3]{master_option} = 1; + $self->$next($info); + }; + + __PACKAGE__->meta->make_immutable; + + no Moose; +} + =head1 HOW TO USE @@ -78,15 +91,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 { @@ -130,27 +136,6 @@ TESTSCHEMACLASSES: { sub cleanup {} ## --------------------------------------------------------------------- ## - ## Add a connect_info option to test option merging. - ## --------------------------------------------------------------------- ## - { - package DBIx::Class::Storage::DBI::Replicated; - - use Moose; - - __PACKAGE__->meta->make_mutable; - - around connect_info => sub { - my ($next, $self, $info) = @_; - $info->[3]{master_option} = 1; - $self->$next($info); - }; - - __PACKAGE__->meta->make_immutable; - - no Moose; - } - - ## --------------------------------------------------------------------- ## ## Subclass for when you are using SQLite for testing, this provides a fake ## replication support. ## --------------------------------------------------------------------- ## @@ -215,10 +200,11 @@ TESTSCHEMACLASSES: { } } - ## Cleanup after ourselves. Unlink all gthe slave paths. + ## Cleanup after ourselves. Unlink all the slave paths. sub cleanup { my $self = shift @_; + $_->disconnect for values %{ $self->schema->storage->replicants }; foreach my $slave (@{$self->slave_paths}) { if(-e $slave) { unlink $slave; @@ -923,6 +909,7 @@ is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{d is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"; } + ## Delete the old database files $replicated->cleanup;