From: Peter Rabbitson Date: Tue, 12 Apr 2016 10:09:03 +0000 (+0200) Subject: Harmonize DBICTEST_VIA_REPLICATED detection in tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=de0edd06a26e5a5f90df64777aeba91968f06c93;p=dbsrgits%2FDBIx-Class-Historic.git Harmonize DBICTEST_VIA_REPLICATED detection in tests Back in 8b60b9211a I made a number of mistakes implementing the escape checks: an envvar being set does not mean we are in fact running under replication (e.g. the user requested explicitly use_file => 0 ) Fix that and also make sure we still run when use_file => 1 (and fix a forgotten test failing this way) --- diff --git a/t/52leaks.t b/t/52leaks.t index 76fc8e6..fffc942 100644 --- a/t/52leaks.t +++ b/t/52leaks.t @@ -59,6 +59,7 @@ my $has_dt; # Skip the heavy-duty leak tracing when just doing an install # or when having Moose crap all over everything +# FIXME - remove when Replicated gets off Moose if ( !$ENV{DBICTEST_VIA_REPLICATED} and !DBICTest::RunMode->is_plain ) { # redefine the bless override so that we can catch each and every object created diff --git a/t/admin/03data.t b/t/admin/03data.t index 460a89e..4be2960 100644 --- a/t/admin/03data.t +++ b/t/admin/03data.t @@ -19,9 +19,13 @@ use DBIx::Class::Admin; sqlite_use_file => 1, ); + my $storage = $schema->storage; + $storage = $storage->master + if $storage->isa('DBIx::Class::Storage::DBI::Replicated'); + my $admin = DBIx::Class::Admin->new( schema_class=> "DBICTest::Schema", - connect_info => $schema->storage->connect_info(), + connect_info => $storage->connect_info(), quiet => 1, _confirm=>1, ); diff --git a/t/icdt/engine_specific/sqlite.t b/t/icdt/engine_specific/sqlite.t index 297372c..1bee9d6 100644 --- a/t/icdt/engine_specific/sqlite.t +++ b/t/icdt/engine_specific/sqlite.t @@ -18,7 +18,7 @@ use DBICTest; my $storage = $schema->storage; - if ($ENV{DBICTEST_VIA_REPLICATED}) { + if( $storage->isa('DBIx::Class::Storage::DBI::Replicated') ) { $storage = $storage->master; } else { diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index e4768a0..2e265b5 100644 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -349,8 +349,11 @@ sub init_schema { my $schema; if ( - $ENV{DBICTEST_VIA_REPLICATED} &&= - ( !$args{storage_type} && !defined $args{sqlite_use_file} ) + $ENV{DBICTEST_VIA_REPLICATED} &&= ( + !$args{storage_type} + && + ( ! defined $args{sqlite_use_file} or $args{sqlite_use_file} ) + ) ) { $args{storage_type} = ['::DBI::Replicated', { balancer_type => '::Random' }]; $args{sqlite_use_file} = 1; diff --git a/t/storage/base.t b/t/storage/base.t index 90cd8f7..df59e91 100644 --- a/t/storage/base.t +++ b/t/storage/base.t @@ -18,7 +18,7 @@ is( ref($storage), 'DBIx::Class::Storage::DBI::SQLite', 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' -) unless $ENV{DBICTEST_VIA_REPLICATED}; +) unless $storage->isa('DBIx::Class::Storage::DBI::Replicated'); throws_ok { $schema->storage->throw_exception('test_exception_42'); @@ -56,7 +56,6 @@ throws_ok { }; } - # testing various invocations of connect_info ([ ... ]) my $coderef = sub { 42 }; diff --git a/t/storage/dbh_do.t b/t/storage/dbh_do.t index 1511f82..07453ea 100644 --- a/t/storage/dbh_do.t +++ b/t/storage/dbh_do.t @@ -10,10 +10,8 @@ use DBICTest; my $schema = DBICTest->init_schema(); my $storage = $schema->storage; - $storage = $storage->master - if $ENV{DBICTEST_VIA_REPLICATED}; - + if $storage->isa('DBIx::Class::Storage::DBI::Replicated'); # test (re)connection for my $disconnect (0, 1) { diff --git a/t/storage/error.t b/t/storage/error.t index e8996fa..710ec22 100644 --- a/t/storage/error.t +++ b/t/storage/error.t @@ -24,7 +24,8 @@ for my $conn_args ( ); my $storage = $s->storage; - $storage = $storage->master if $ENV{DBICTEST_VIA_REPLICATED}; + $storage = $storage->master + if $storage->isa('DBIx::Class::Storage::DBI::Replicated'); ok( ! $storage->connected, 'Starting unconnected' ); @@ -49,7 +50,8 @@ for my $conn_args ( my $s = DBICTest->init_schema( no_deploy => 1, @$conn_args ); my $storage = $s->storage; - $storage = $storage->master if $ENV{DBICTEST_VIA_REPLICATED}; + $storage = $storage->master + if $storage->isa('DBIx::Class::Storage::DBI::Replicated'); my $desc = "broken on_disconnect action @{[ explain $conn_args ]}";