X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FDBICTest.pm;h=c0c91c276886cf8656f168764d96cec66c45e9a1;hb=db83437ef48f4571e1d225572cc7235eb5e64fe3;hp=f2b27733fa5230912816309669014ac7772eabc1;hpb=b74b15b066a19f07b575883abd397ea4d3b045db;p=dbsrgits%2FDBIx-Class.git diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index f2b2773..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; } } @@ -219,7 +235,7 @@ sub _database { # set a *DBI* disconnect callback, to make sure the physical SQLite # file is still there (i.e. the test does not attempt to delete # an open database, which fails on Win32) - if (my $guard_cb = __mk_disconnect_guard($db_file)) { + if (! $storage->{master} and my $guard_cb = __mk_disconnect_guard($db_file)) { $dbh->{Callbacks} = { connect => sub { $guard_cb->('connect') }, disconnect => sub { $guard_cb->('disconnect') }, @@ -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 ) { @@ -320,6 +337,14 @@ sub init_schema { my $schema; + if ( + $ENV{DBICTEST_VIA_REPLICATED} &&= + ( !$args{storage_type} && !defined $args{sqlite_use_file} ) + ) { + $args{storage_type} = ['::DBI::Replicated', { balancer_type => '::Random' }]; + $args{sqlite_use_file} = 1; + } + my @dsn = $self->_database(%args); if ($args{compose_connection}) { @@ -337,6 +362,9 @@ sub init_schema { if ( !$args{no_connect} ) { $schema->connection(@dsn); + + $schema->storage->connect_replicants(\@dsn) + if $ENV{DBICTEST_VIA_REPLICATED}; } if ( !$args{no_deploy} ) { @@ -375,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); @@ -406,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/],