From c20f46a6b63dc3beb92eb0d62c82999fde14686b Mon Sep 17 00:00:00 2001 From: Kieron Taylor <ktaylor@ebi.ac.uk> Date: Mon, 21 Jan 2013 16:22:49 +0000 Subject: [PATCH] Tweaked test to allow single-threaded runs. Possible insert race condition will not be exposed. --- modules/t/dbEntries.t | 67 ++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/modules/t/dbEntries.t b/modules/t/dbEntries.t index d7dc4d2174..f74400887e 100644 --- a/modules/t/dbEntries.t +++ b/modules/t/dbEntries.t @@ -198,35 +198,46 @@ $xref = Bio::EnsEMBL::DBEntry->new -analysis => $analysis ); -{ - local $ENV{RUNTESTS_HARNESS} = 1; - local $ENV{RUNTESTS_HARNESS_NORESTORE} = 1; - - # db connection must be severed for threads to access DB - $dbEntryAdaptor->dbc->disconnect_if_idle(); - $multi->get_DBAdaptor('empty'); # seem to have to do this to stop thread whinging under some perls - use threads; - - my $parallel_store = sub{ - 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 $threaded; + use Config; + if($Config{useithreads}) { + note 'Using threaded tests'; + require threads; + $threaded = 1; + { + local $ENV{RUNTESTS_HARNESS} = 1; + local $ENV{RUNTESTS_HARNESS_NORESTORE} = 1; + + # db connection must be severed for threads to access DB + $dbEntryAdaptor->dbc->disconnect_if_idle(); + $multi->get_DBAdaptor('empty'); # seem to have to do this to stop thread whinging under some perls + my $parallel_store = sub{ + 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]); - my @xref_ids; - @xref_ids = ($thread1->join,$thread2->join,$thread3->join); + # Test 10 - Verify that only one xref has been inserted under parallel inserts + is($xref_ids[0], 1000009, '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'); + } - note("Threaded xrefs: ".$xref_ids[0]." ".$xref_ids[1]." ".$xref_ids[2]); + } + else { + note 'Skipping threaded tests'; + } - # Test 10 - Verify that only one xref has been inserted under parallel inserts - is($xref_ids[0], 1000009, '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'); -} # Test 11 - Exception testing on ->store() @@ -248,7 +259,11 @@ $xref = Bio::EnsEMBL::DBEntry->new my $xref_id = $dbEntryAdaptor->store($xref, undef, "Transcript"); note("Xref_id from insert: ".$xref_id); -ok($xref_id == 1000010); +if ($threaded) { + ok($xref_id == 1000010); +} else { + is($xref_id,1000009, "dbID for new DBEntry."); +} # # 12-14 Test that external synonyms and go evidence tags are retrieved -- GitLab