From 2e7ce8be132ce7f8b1b4fa04a88264569321c07f Mon Sep 17 00:00:00 2001
From: Magali Ruffier <mr6@ebi.ac.uk>
Date: Thu, 8 Aug 2013 10:20:22 +0000
Subject: [PATCH] dealing with threaded entries when inserting 3 entries in
 parallel, should only store once but depending on how fast mysql catches up,
 the return dbID corresponds to the first or the last attempt now allowing for
 this change of mind

---
 modules/t/dbEntries.t | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/modules/t/dbEntries.t b/modules/t/dbEntries.t
index 77c2738922..dde4c1fa8c 100644
--- a/modules/t/dbEntries.t
+++ b/modules/t/dbEntries.t
@@ -198,12 +198,11 @@ $xref = Bio::EnsEMBL::DBEntry->new
     -analysis => $analysis
    );
 
-my $threaded;
 use Config;
+my $stored_xref_id = 1000002;
 if($Config{useithreads}) {
   note 'Using threaded tests';
   require threads;
-  $threaded = 1;
   {
     local $ENV{RUNTESTS_HARNESS} = 1;
     local $ENV{RUNTESTS_HARNESS_NORESTORE} = 1;
@@ -228,9 +227,10 @@ if($Config{useithreads}) {
     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
-    is($xref_ids[0], 1000003, 'Thread 1 ID assertion');
     is($xref_ids[1], $xref_ids[0], 'Thread 2 ID is the same as thread 1');
     is($xref_ids[2], $xref_ids[0], 'Thread 3 ID is the same as thread 1');
+
+    $stored_xref_id = $xref_ids[0];
   }
 
 }
@@ -259,11 +259,7 @@ $xref = Bio::EnsEMBL::DBEntry->new
    
 my $xref_id = $dbEntryAdaptor->store($xref, undef, "Transcript");
 note("Xref_id from insert: ".$xref_id);
-if ($threaded) {
-  ok($xref_id == 1000004);   
-} else {
-  is($xref_id,1000003, "dbID for new DBEntry.");
-}
+is($xref_id, $stored_xref_id + 1, "dbID for new DBEntry.");
 
 #
 # 12-14 Test that external synonyms and go evidence tags are retrieved
@@ -552,4 +548,4 @@ sub print_dbEntries {
 
 }
 
-done_testing();
\ No newline at end of file
+done_testing();
-- 
GitLab