From 5009ec78c01e31fcdef2a23e70fd1608c8129da8 Mon Sep 17 00:00:00 2001
From: Andrew Yates <ayates@ebi.ac.uk>
Date: Mon, 18 Jun 2012 21:30:56 +0000
Subject: [PATCH] Stop accidental cleanup of databases during object cleanup

---
 modules/t/dbEntries.t | 44 ++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/modules/t/dbEntries.t b/modules/t/dbEntries.t
index f7d1d9e672..aca7d9e649 100644
--- a/modules/t/dbEntries.t
+++ b/modules/t/dbEntries.t
@@ -197,27 +197,33 @@ $xref = Bio::EnsEMBL::DBEntry->new
    -type => "ARRAY",
     -analysis => $analysis
    );
-# db connection must be severed for threads to access DB    
-$dbEntryAdaptor->dbc->disconnect_if_idle();
-use threads;
 
-sub parallel_store {
-    my $xref_id = $dbEntryAdaptor->store( $xref, $tr->dbID, "Transcript" );
-    return $xref_id
-}
-   
-my $thread1 = threads->create(\&parallel_store);
-my $thread2 = threads->create(\&parallel_store);
-my $thread3 = threads->create(\&parallel_store);
-
-    
-my @xref_ids;
-@xref_ids = ($thread1->join,$thread2->join,$thread3->join);
-
-note("Threaded xrefs: ".$xref_ids[0]." ".$xref_ids[1]." ".$xref_ids[2]);
+{
+  local $ENV{RUNTESTS_HARNESS} = 1;
+  
+  # db connection must be severed for threads to access DB    
+  $dbEntryAdaptor->dbc->disconnect_if_idle();
+  use threads;
+  
+  sub parallel_store {
+      my $xref_id = $dbEntryAdaptor->store( $xref, $tr->dbID, "Transcript" );
+      return $xref_id
+  }
+     
+  my $thread1 = threads->create(\&parallel_store);
+  my $thread2 = threads->create(\&parallel_store);
+  my $thread3 = threads->create(\&parallel_store);
+  
+      
+  my @xref_ids;
+  @xref_ids = ($thread1->join,$thread2->join,$thread3->join);
+  
+  note("Threaded xrefs: ".$xref_ids[0]." ".$xref_ids[1]." ".$xref_ids[2]);
+  
+  # Test 10 - Verify that only one xref has been inserted under parallel inserts
+  ok($xref_ids[0] == 1000009 && $xref_ids[1] == $xref_ids[0] && $xref_ids[2] == $xref_ids[0]);
 
-# Test 10 - Verify that only one xref has been inserted under parallel inserts
-ok($xref_ids[0] == 1000009 && $xref_ids[1] == $xref_ids[0] && $xref_ids[2] == $xref_ids[0]);
+}
 
 # Test 11 - Exception testing on ->store()
 
-- 
GitLab