Commit 954e0809 authored by Andy Yates's avatar Andy Yates
Browse files

better handling of a missing DB and missing internet connection

parent 80ea9e06
......@@ -11,6 +11,17 @@ use File::Spec::Functions qw/updir catfile catdir/;
use File::Temp qw/tempfile/;
use FindBin qw/$Bin/;
#Assume if ensembl.org is down then there is no point in continuing with the tests (1 shot)
sub test_ensembl {
my $content = eval { do_GET('http://www.ensembl.org', 1); };
my $success = 1;
if($@) {
note 'ensembl.org is unreachable. Cannot continue with tests';
$success = 0;
}
return $success;
}
sub get_url {
my ($url) = @_;
my $content = eval { do_GET($url, 5, 0.5); };
......@@ -20,30 +31,32 @@ sub get_url {
return;
}
my $db = Bio::EnsEMBL::Test::MultiTestDB->new();
my $dba = $db->get_DBAdaptor('core');
my $dbc = $dba->dbc();
SKIP: {
#Get last DB version and download the last SQL schema
my $current_release = software_version();
my $last_release = $current_release - 1;
my $cvs_url = "http://cvs.sanger.ac.uk/cgi-bin/viewvc.cgi/ensembl/sql/table.sql?root=ensembl&view=co&pathrev=branch-ensembl-${last_release}";
my $table_sql = get_url($cvs_url);
my $ensembl_ok = test_ensembl();
skip 'Cannot communicate with ensembl.org. We cannot continue with the tests', 1 unless $ensembl_ok;
# Get patch location
my $sql_dir = catdir($Bin, updir(), updir(), 'sql');
my @patches;
find(sub {
if($_ =~ /^patch_${last_release}_${current_release}_\w+\.sql$/) {
push(@patches, $File::Find::name);
}
}, $sql_dir);
#Get last DB version and download the last SQL schema
my $current_release = software_version();
my $last_release = $current_release - 1;
my $cvs_url = "http://cvs.sanger.ac.uk/cgi-bin/viewvc.cgi/ensembl/sql/table.sql?root=ensembl&view=co&pathrev=branch-ensembl-${last_release}";
my $table_sql = get_url($cvs_url);
my $new_db_name = $db->create_db_name('schemapatchestemp');
# Get patch location
my $sql_dir = catdir($Bin, updir(), updir(), 'sql');
my @patches;
find(sub {
if($_ =~ /^patch_${last_release}_${current_release}_\w+\.sql$/) {
push(@patches, $File::Find::name);
}
}, $sql_dir);
SKIP: {
skip 'Skipping DB patch tests as we cannot find the SQL at URL '.$cvs_url, (scalar(@patches)+1) unless defined $table_sql;
my $db = Bio::EnsEMBL::Test::MultiTestDB->new();
my $dba = $db->get_DBAdaptor('core');
my $dbc = $dba->dbc();
my $new_db_name = $db->create_db_name('schemapatchestemp');
my ($fh, $sql_schema_file) = tempfile();
print $fh $table_sql;
......@@ -78,10 +91,10 @@ SKIP: {
foreach my $patch (@patches) {
note "Applying patch $patch";
$load_sql->($patch);
}
}
note 'Dropping database '.$new_db_name;
$dba->dbc()->do("drop database if exists $new_db_name");
}
note 'Dropping database '.$new_db_name;
$dba->dbc()->do("drop database if exists $new_db_name");
done_testing();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment