From: Peter Rabbitson Date: Sat, 2 Apr 2016 13:21:37 +0000 (+0200) Subject: Test with explicitly readonly 'replicants' under DBICTEST_VIA_REPLICATED X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf726d9cd6f7e53d6b3eb540d899e494f245fb5a;p=dbsrgits%2FDBIx-Class-Historic.git Test with explicitly readonly 'replicants' under DBICTEST_VIA_REPLICATED --- diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index d09a9dc..e4768a0 100644 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -32,7 +32,7 @@ use DBICTest::Util qw( ); use DBICTest::Util::LeakTracer qw/populate_weakregistry assert_empty_weakregistry/; use DBICTest::Schema; -use DBIx::Class::_Util qw( detected_reinvoked_destructor scope_guard ); +use DBIx::Class::_Util qw( detected_reinvoked_destructor scope_guard modver_gt_or_eq ); use Carp; use Fcntl qw/:DEFAULT :flock/; use Config; @@ -374,8 +374,19 @@ sub init_schema { if ( !$args{no_connect} ) { $schema->connection(@dsn); - $schema->storage->connect_replicants(\@dsn) - if $ENV{DBICTEST_VIA_REPLICATED}; + if( $ENV{DBICTEST_VIA_REPLICATED} ) { + + # add explicit ReadOnly=1 if we can support it + $dsn[0] =~ /^dbi:SQLite:/i + and + require DBD::SQLite + and + modver_gt_or_eq('DBD::SQLite', '1.49_05') + and + $dsn[0] =~ s/^dbi:SQLite:/dbi:SQLite(ReadOnly=1):/i; + + $schema->storage->connect_replicants(\@dsn); + } } if ( !$args{no_deploy} ) { diff --git a/t/lib/DBICTest/BaseSchema.pm b/t/lib/DBICTest/BaseSchema.pm index 2663530..4fa2f20 100644 --- a/t/lib/DBICTest/BaseSchema.pm +++ b/t/lib/DBICTest/BaseSchema.pm @@ -242,7 +242,12 @@ sub connection { # this will either give us an undef $locktype or will determine things # properly with a default ( possibly connecting in the process ) eval { - my $s = ref($self)->connect(@{$self->storage->connect_info})->storage; + my $cur_storage = $self->storage; + + $cur_storage = $cur_storage->master + if $cur_storage->isa('DBIx::Class::Storage::DBI::Replicated'); + + my $s = ref($self)->connect(@{$cur_storage->connect_info})->storage; $locktype = $s->sqlt_type || 'generic';