Commit aa336053 authored by Leo Gordon's avatar Leo Gordon
Browse files

safe_drop_database is a new Utils::Test method to wait for Workers to exit,...

safe_drop_database is a new Utils::Test method to wait for Workers to exit, disconnect and drop the DB
parent 13e7edad
......@@ -45,7 +45,7 @@ use Bio::EnsEMBL::Hive::Scripts::StandaloneJob;
our @ISA = qw(Exporter);
our @EXPORT = ();
our %EXPORT_TAGS = ();
our @EXPORT_OK = qw( standaloneJob init_pipeline runWorker beekeeper generate_graph visualize_jobs seed_pipeline get_test_urls get_test_url_or_die run_sql_on_db load_sql_in_db make_new_db_from_sqls make_hive_db );
our @EXPORT_OK = qw( standaloneJob init_pipeline runWorker beekeeper generate_graph visualize_jobs seed_pipeline get_test_urls get_test_url_or_die run_sql_on_db load_sql_in_db make_new_db_from_sqls make_hive_db safe_drop_database);
our $VERSION = '0.00';
......@@ -573,4 +573,30 @@ sub get_test_url_or_die {
return (sort @$list_of_urls)[0];
}
=head2 safe_drop_database
Arg[1] : DBAdaptor $hive_dba
Example : safe_drop_database( $hive_dba );
Description : Wait for all workers to complete, disconnect from the database and drop it.
Returntype : None
Caller : test scripts
=cut
sub safe_drop_database {
my $hive_dba = shift;
# In case workers are still alive:
my $worker_adaptor = $hive_dba->get_WorkerAdaptor;
while( $worker_adaptor->count_all("status != 'DEAD'") ) {
sleep(1);
}
my $dbc = $hive_dba->dbc;
$dbc->disconnect_if_idle();
run_sql_on_db($dbc->url, 'DROP DATABASE');
}
1;
......@@ -22,7 +22,7 @@ use warnings;
use Test::More;
use Data::Dumper;
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper get_test_url_or_die run_sql_on_db);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper get_test_url_or_die safe_drop_database);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
......@@ -67,13 +67,7 @@ foreach my $url ($client_url, $server_url) {
sprintf("%s*%s=%s", $_->{'a_multiplier'}, $_->{'b_multiplier'}, $_->{'result'}) );
}
# In case workers are still alive
while ($hive_dba->get_WorkerAdaptor->count_all("status != 'DEAD'")) {
sleep(1);
}
$hive_dba->dbc->disconnect_if_idle();
run_sql_on_db($url, 'DROP DATABASE');
safe_drop_database( $hive_dba );
}
done_testing();
......
......@@ -23,7 +23,7 @@ use Test::More;
use Data::Dumper;
use Bio::EnsEMBL::Hive::TheApiary;
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper run_sql_on_db get_test_url_or_die);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper get_test_url_or_die safe_drop_database);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
......@@ -74,17 +74,9 @@ foreach my $url ($client_url, $server_url) {
}
}
# In case workers are still alive
while ($hive_dba->get_WorkerAdaptor->count_all("status != 'DEAD'")) {
sleep(1);
}
$hive_dba->dbc->disconnect_if_idle();
safe_drop_database( $hive_dba );
}
foreach my $url ($client_url, $server_url) {
run_sql_on_db($url, 'DROP DATABASE');
}
done_testing();
......@@ -23,7 +23,7 @@ use Test::More;
use Data::Dumper;
use File::Temp qw{tempdir};
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper get_test_url_or_die run_sql_on_db);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper get_test_url_or_die safe_drop_database);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
......@@ -102,8 +102,7 @@ warn "\nInitializing the $gcpct_version pipeline ...\n\n";
my $beekeeper_options_string = join(' ', '-url', $hive_dba->dbc->url('EHIVE_PASS'), @beekeeper_options);
is($beekeeper_row->{'options'}, $beekeeper_options_string, 'beekeeper options stored correctly');
$hive_dba->dbc->disconnect_if_idle();
run_sql_on_db($pipeline_url, 'DROP DATABASE');
safe_drop_database( $hive_dba );
}
}
......
......@@ -26,7 +26,7 @@ use Test::More;
use Data::Dumper;
use Bio::EnsEMBL::Hive::Utils ('find_submodules');
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper seed_pipeline get_test_url_or_die run_sql_on_db);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper seed_pipeline get_test_url_or_die safe_drop_database);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
......@@ -83,8 +83,7 @@ foreach my $long_mult_version ( @pipeline_cfgs ) {
sprintf("%s*%s=%s", $_->{'a_multiplier'}, $_->{'b_multiplier'}, $_->{'result'}) );
}
$hive_dba->dbc->disconnect_if_idle();
run_sql_on_db($pipeline_url, 'DROP DATABASE');
safe_drop_database( $hive_dba );
} # /SKIP
}
......
......@@ -24,7 +24,7 @@ use Data::Dumper;
use File::Temp qw{tempdir};
use Bio::EnsEMBL::Hive::Utils ('find_submodules');
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker get_test_url_or_die run_sql_on_db);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker get_test_url_or_die safe_drop_database);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
......@@ -138,8 +138,8 @@ my $pipeline_url = get_test_url_or_die();
ok ( 520 == $total_kmers,
sprintf("%f kmers found in input FASTQ file", , $total_kmers));
}
$hive_dba->dbc->disconnect_if_idle();
run_sql_on_db($pipeline_url, 'DROP DATABASE');
safe_drop_database( $hive_dba );
}
}
......
......@@ -21,7 +21,7 @@ use warnings;
use Test::More;
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker get_test_url_or_die run_sql_on_db);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker get_test_url_or_die safe_drop_database);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
......@@ -61,8 +61,7 @@ my $semaphore = shift @semaphores;
is($semaphore->local_jobs_counter, $fan_job_count, 'All the fan jobs share the same semaphore');
$hive_dba->dbc->disconnect_if_idle();
run_sql_on_db($pipeline_url, 'DROP DATABASE');
safe_drop_database( $hive_dba );
done_testing();
......@@ -26,7 +26,7 @@ use Test::More;
use Data::Dumper;
use Bio::EnsEMBL::Hive::Utils ('find_submodules');
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper seed_pipeline get_test_urls run_sql_on_db);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper seed_pipeline get_test_urls safe_drop_database);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
......@@ -81,13 +81,7 @@ foreach my $long_mult_version ( @pipeline_cfgs ) {
sprintf("%s*%s=%s", $_->{'a_multiplier'}, $_->{'b_multiplier'}, $_->{'result'}) );
}
# In case workers are still alive
while ($hive_dba->get_WorkerAdaptor->count_all("status != 'DEAD'")) {
sleep(1);
}
$hive_dba->dbc->disconnect_if_idle();
run_sql_on_db($pipeline_url, 'DROP DATABASE');
safe_drop_database( $hive_dba );
}
}
......
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