From: Peter Rabbitson <ribasushi@cpan.org>
Date: Tue, 17 Mar 2015 12:06:13 +0000 (+0100)
Subject: Fix test suite to work again with DBICTEST_SQLITE_USE_FILE
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ee5733658f9bca488689f85a61c9cd7092138f85;p=dbsrgits%2FDBIx-Class-Historic.git

Fix test suite to work again with DBICTEST_SQLITE_USE_FILE

It was never included as part of POISON_ENV and subsequently lapsed. Sigh.
---

diff --git a/maint/travis-ci_scripts/20_install.bash b/maint/travis-ci_scripts/20_install.bash
index f67cd8b..054b908 100755
--- a/maint/travis-ci_scripts/20_install.bash
+++ b/maint/travis-ci_scripts/20_install.bash
@@ -86,6 +86,7 @@ if [[ "$POISON_ENV" = "true" ]] ; then
   # returned results, look through lib, find all mentioned ENVvars and
   # set them to true and see if anything explodes
   for var in \
+    DBICTEST_SQLITE_USE_FILE \
     DBICTEST_RUN_ALL_TESTS \
     DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER \
     $( grep -P '\$ENV\{' -r lib/ --exclude-dir Optional | grep -oP '\bDBIC\w+' | sort -u | grep -vP '^(DBIC_TRACE(_PROFILE)?|DBIC_.+_DEBUG)$' )
diff --git a/t/40compose_connection.t b/t/40compose_connection.t
index a68a2c2..051ab9b 100644
--- a/t/40compose_connection.t
+++ b/t/40compose_connection.t
@@ -16,7 +16,4 @@ warnings_exist { DBICTest->init_schema( compose_connection => 1, sqlite_use_file
 
 cmp_ok(DBICTest->resultset('Artist')->count, '>', 0, 'count is valid');
 
-# cleanup globaly cached handle so we do not trigger the leaktest
-DBICTest->schema->storage->disconnect;
-
 done_testing;
diff --git a/t/cdbi/sweet/08pager.t b/t/cdbi/sweet/08pager.t
index e14c4fa..7f94e51 100644
--- a/t/cdbi/sweet/08pager.t
+++ b/t/cdbi/sweet/08pager.t
@@ -63,15 +63,4 @@ is( $it->next, undef, "disable_sql_paging next past end of page ok" );
 );
 is( $it->count, 1, "complex abstract count ok" );
 
-# cleanup globals so we do not trigger the leaktest
-for ( map { DBICTest->schema->class($_) } DBICTest->schema->sources ) {
-  $_->class_resolver(undef);
-  $_->resultset_instance(undef);
-  $_->result_source_instance(undef);
-}
-{
-  no warnings qw/redefine once/;
-  *DBICTest::schema = sub {};
-}
-
 done_testing;
diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm
index a3b5f2f..fa92a95 100644
--- a/t/lib/DBICTest.pm
+++ b/t/lib/DBICTest.pm
@@ -143,6 +143,7 @@ END {
 
 $SIG{INT} = sub { _cleanup_dbfile(); exit 1 };
 
+my $need_global_cleanup;
 sub _cleanup_dbfile {
     # cleanup if this is us
     if (
@@ -152,6 +153,10 @@ sub _cleanup_dbfile {
         or
       $ENV{DBICTEST_LOCK_HOLDER} == $$
     ) {
+        if ($need_global_cleanup and my $dbh = DBICTest->schema->storage->_dbh) {
+          $dbh->disconnect;
+        }
+
         my $db_file = _sqlite_dbfilename();
         unlink $_ for ($db_file, "${db_file}-journal");
     }
@@ -316,6 +321,7 @@ sub init_schema {
     my $schema;
 
     if ($args{compose_connection}) {
+      $need_global_cleanup = 1;
       $schema = DBICTest::Schema->compose_connection(
                   'DBICTest', $self->_database(%args)
                 );
diff --git a/t/prefetch/correlated.t b/t/prefetch/correlated.t
index fdbd262..5196620 100644
--- a/t/prefetch/correlated.t
+++ b/t/prefetch/correlated.t
@@ -129,6 +129,8 @@ is_same_sql_bind(
   'Expected SQL on correlated realiased subquery'
 );
 
+$schema->storage->disconnect;
+
 # test for subselect identifier leakage
 # NOTE - the hodge-podge mix of literal and regular identifuers is *deliberate*
 for my $quote_names (0,1) {
diff --git a/t/storage/base.t b/t/storage/base.t
index df3641e..1861855 100644
--- a/t/storage/base.t
+++ b/t/storage/base.t
@@ -146,6 +146,8 @@ for my $type (keys %$invocations) {
   );
 }
 
+$schema->storage->_dbh->disconnect;
+
 # make sure connection-less storages do not throw on _determine_driver
 # but work with ENV at the same time
 SKIP: for my $env_dsn (undef, (DBICTest->_database)[0] ) {