Prevent DBD::Firebird and DBD::InterBase from colliding on same DSN
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema.pm
index b77c0d7..61a4386 100644 (file)
@@ -74,7 +74,7 @@ our $locker;
 END {
   # we need the $locker to be referenced here for delayed destruction
   if ($locker->{lock_name} and ($ENV{DBICTEST_LOCK_HOLDER}||0) == $$) {
-    #warn "$$ $0 $locktype LOCK RELEASED";
+    #warn "$$ $0 $locker->{type} LOCK RELEASED";
   }
 }
 
@@ -144,12 +144,27 @@ sub connection {
       ;
     };
 
+    # DBD::Firebird and DBD::InterBase could very well talk to the same RDBMS
+    # make an educated guesstimate based on the DSN
+    # (worst case scenario we are wrong and the scripts have to wait on each
+    # other even without actually being able to interfere among themselves)
+    if (
+      ($locktype||'') eq 'InterBase'
+        and
+      $_[0] =~ /firebird/i
+    ) {
+      $locktype = 'Firebird';
+    }
 
     # Never hold more than one lock. This solves the "lock in order" issues
     # unrelated tests may have
     # Also if there is no connection - there is no lock to be had
     if ($locktype and (!$locker or $locker->{type} ne $locktype)) {
 
+      # this will release whatever lock we may currently be holding
+      # which is fine since the type does not match as checked above
+      undef $locker;
+
       my $lockpath = DBICTest::RunMode->tmpdir->file(".dbictest_$locktype.lock");
 
       #warn "$$ $0 $locktype GRABBING LOCK";