X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FDBICTest.pm;h=c0c91c276886cf8656f168764d96cec66c45e9a1;hb=5c505cafa292b25dbbfb0df53ac30e73069834a2;hp=39a8af926c088f30775b455679b96c8967ea4f68;hpb=8b60b9211a085572446bbfd19e879d00ae03658a;p=dbsrgits%2FDBIx-Class.git diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 39a8af9..c0c91c2 100644 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -4,10 +4,10 @@ package # hide from PAUSE use strict; use warnings; -use DBICTest::Util 'local_umask'; +use DBICTest::Util qw( local_umask await_flock dbg DEBUG_TEST_CONCURRENCY_LOCKS ); use DBICTest::Schema; use DBICTest::Util::LeakTracer qw/populate_weakregistry assert_empty_weakregistry/; -use DBIx::Class::_Util 'detected_reinvoked_destructor'; +use DBIx::Class::_Util qw( detected_reinvoked_destructor scope_guard ); use Carp; use Path::Class::File (); use File::Spec; @@ -90,7 +90,14 @@ sub import { for my $exp (@_) { if ($exp eq ':GlobalLock') { - flock ($global_lock_fh, LOCK_EX) or die "Unable to lock $lockpath: $!"; + DEBUG_TEST_CONCURRENCY_LOCKS > 1 + and dbg "Waiting for EXCLUSIVE global lock..."; + + await_flock ($global_lock_fh, LOCK_EX) or die "Unable to lock $lockpath: $!"; + + DEBUG_TEST_CONCURRENCY_LOCKS > 1 + and dbg "Got EXCLUSIVE global lock"; + $global_exclusive_lock = 1; } elsif ($exp eq ':DiffSQL') { @@ -107,13 +114,22 @@ sub import { } unless ($global_exclusive_lock) { - flock ($global_lock_fh, LOCK_SH) or die "Unable to lock $lockpath: $!"; + DEBUG_TEST_CONCURRENCY_LOCKS > 1 + and dbg "Waiting for SHARED global lock..."; + + await_flock ($global_lock_fh, LOCK_SH) or die "Unable to lock $lockpath: $!"; + + DEBUG_TEST_CONCURRENCY_LOCKS > 1 + and dbg "Got SHARED global lock"; } } END { + # referencing here delays destruction even more if ($global_lock_fh) { - # delay destruction even more + DEBUG_TEST_CONCURRENCY_LOCKS > 1 + and dbg "Release @{[ $global_exclusive_lock ? 'EXCLUSIVE' : 'SHARED' ]} global lock (END)"; + 1; } } @@ -267,6 +283,7 @@ sub __mk_disconnect_guard { return; } elsif ($event eq 'disconnect') { + return unless $connected; # we already disconnected earlier $connected = 0; } elsif ($event eq 'DESTROY' and ! $connected ) { @@ -386,8 +403,11 @@ sub deploy_schema { my $schema = shift; my $args = shift || {}; - local $schema->storage->{debug} - if ($ENV{TRAVIS}||'') eq 'true'; + my $guard; + if ( ($ENV{TRAVIS}||'') eq 'true' and my $old_dbg = $schema->storage->debug ) { + $guard = scope_guard { $schema->storage->debug($old_dbg) }; + $schema->storage->debug(0); + } if ($ENV{"DBICTEST_SQLT_DEPLOY"}) { $schema->deploy($args); @@ -417,8 +437,11 @@ sub populate_schema { my $self = shift; my $schema = shift; - local $schema->storage->{debug} - if ($ENV{TRAVIS}||'') eq 'true'; + my $guard; + if ( ($ENV{TRAVIS}||'') eq 'true' and my $old_dbg = $schema->storage->debug ) { + $guard = scope_guard { $schema->storage->debug($old_dbg) }; + $schema->storage->debug(0); + } $schema->populate('Genre', [ [qw/genreid name/],