Newer
Older
Andy Yates
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
use Config;
use Test::More;
use File::Temp qw/tempfile/;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Test::MultiTestDB;
my $threads;
if($Config{useithreads}) {
note 'Using threaded tests';
require threads;
$threads = 1;
}
else {
note 'Using non-threaded tests';
}
my $multi_db = Bio::EnsEMBL::Test::MultiTestDB->new();
my $db = $multi_db->get_DBAdaptor('core');
my $dbc = $db->dbc();
my $reg = 'Bio::EnsEMBL::Registry';
my $registry_template = <<'TMPL';
{
package Reg;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
Bio::EnsEMBL::DBSQL::DBAdaptor->new(
-HOST => '%s',
-PORT => %d,
-USER => '%s',
-PASSWORD => '%s',
-DBNAME => '%s',
-DRIVER => 'mysql',
-SPECIES => 'new'
);
}
1;
TMPL
{
my ($fh, $filename) = tempfile();
my $final = sprintf($registry_template, $dbc->host(), $dbc->port(), $dbc->username(), $dbc->password(), $dbc->dbname());
print $fh $final;
close $fh;
my $call = sub {
my @results;
foreach my $inc (0..9) {
push(@results, $reg->load_all($filename));
}
return \@results;
};
if($threads) {
Andy Yates
committed
$ENV{RUNTESTS_HARNESS_NORESTORE} = 1;
Andy Yates
committed
my @thrds;
foreach my $thr (0..9) {
push(@thrds, threads->create($call));
}
foreach my $thr (@thrds) {
my $results = $thr->join();
my $msg = sprintf('THREAD %s: Checking first call loaded 1 DBAdaptor and the remaining 9 did nothing', $thr->tid());
is_deeply($results, [1, ((0)x9)], $msg);
}
}
else {
foreach my $itr (0..9) {
$call->();
}
Andy Yates
committed
}
}
done_testing();