Skip to content

Commit

Permalink
Test init_pipeline outside of the test process.
Browse files Browse the repository at this point in the history
init_pipeline was the last script tested this way. That caused some
issues because it is not isolated from the test process, and for
instance it will register the pipeline in TheApiary. Also, the test is
more reliable if the actual script is tested.
  • Loading branch information
muffato committed Oct 6, 2020
1 parent d5a5e79 commit e6e1390
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 35 deletions.
19 changes: 5 additions & 14 deletions modules/Bio/EnsEMBL/Hive/Utils/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,11 @@ sub init_pipeline {
$url = (splice(@$options, $url_flag_index, 2))[1];
}

local @ARGV = @$options;
unshift @ARGV, (-pipeline_url => $url, -hive_force_init => 1);

lives_ok(sub {
my $orig_unambig_url = Bio::EnsEMBL::Hive::Utils::URL::parse($url)->{'unambig_url'};
ok($orig_unambig_url, 'Given URL could be parsed');
my $returned_url = Bio::EnsEMBL::Hive::Scripts::InitPipeline::init_pipeline($file_or_module, $tweaks);
ok($returned_url, 'pipeline initialized on '.$returned_url);

my $returned_unambig_url = Bio::EnsEMBL::Hive::Utils::URL::parse($returned_url)->{'unambig_url'};
# Both $url and $returned_url MAY contain the password (if applicable for the driver) but can be missing the port number assuming a default
# Both $orig_unambig_url and $returned_unambig_url SHOULD contain the port number (if applicable for the driver) but WILL NOT contain a password
is($returned_unambig_url, $orig_unambig_url, 'pipeline initialized on '.$url);
}, sprintf('init_pipeline("%s", %s)', $file_or_module, stringify($options)));
my @args = ($file_or_module, -pipeline_url => $url, -hive_force_init => 1);
push @args, @$options;
push @args, map {-tweak => $_} @$tweaks if $tweaks;

return _test_ehive_script('init_pipeline', undef, \@args);
}


Expand Down
2 changes: 1 addition & 1 deletion t/02.api/fetch_and_count_by_multiple_columns.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ my $ehive_test_pipeline_urls = get_test_urls();
foreach my $pipeline_url (@$ehive_test_pipeline_urls) {

subtest 'Test on '.$pipeline_url, sub {
plan tests => 20;
plan tests => 17;

init_pipeline('Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMult_conf', $pipeline_url);

Expand Down
18 changes: 8 additions & 10 deletions t/03.scripts/generate_graph.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ GetOptions(

my $server_url = get_test_url_or_die(-tag => 'server', -no_user_prefix => 1);

# Most of the test scripts test init_pipeline() from Utils::Test but we
# also need to test the main scripts/init_pipeline.pl !
my @init_pipeline_args = ($ENV{'EHIVE_ROOT_DIR'}.'/scripts/init_pipeline.pl', 'Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMultServer_conf', -pipeline_url => $server_url, -hive_force_init => 1, -tweak => 'pipeline.param[take_time]=0');
test_command(\@init_pipeline_args);
init_pipeline(
'Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMultServer_conf',
$server_url,
[],
[
'pipeline.param[take_time]=0',
],
);


my $client_url = get_test_url_or_die(-tag => 'client', -no_user_prefix => 1);
Expand All @@ -59,12 +63,6 @@ push @confs_to_test, 'GC::PipeConfig::GCPct_conf' unless $@; # SKIP it in cas
my ($fh, $tmp_filename) = tempfile(UNLINK => 1);
close($fh);

sub test_command {
my $cmd_array = shift;
ok(!system(@$cmd_array), 'Can run '.join(' ', @$cmd_array));
}


foreach my $conf (@confs_to_test) {
subtest $conf, sub {
my $module_name = 'Bio::EnsEMBL::Hive::Examples::'.$conf;
Expand Down
3 changes: 1 addition & 2 deletions t/10.pipeconfig/analysis_heir.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Fil
my $pipeline_url = get_test_url_or_die();

my $init_stderr = capture_stderr {
local @INC = @INC;
push @INC, $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/';
local $ENV{'PERL5LIB'} = $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB};
init_pipeline(
'TestPipeConfig::MissingAnalysis_conf',
$pipeline_url,
Expand Down
3 changes: 1 addition & 2 deletions t/10.pipeconfig/gc_dataflow.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Fil
my $pipeline_url = get_test_url_or_die();

{
local @INC = @INC;
push @INC, $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/';
local $ENV{'PERL5LIB'} = $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB};
init_pipeline('TestPipeConfig::AnyFailureBranch_conf', $pipeline_url, [], ['pipeline.param[take_time]=100']);
}
my $hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new( -url => $pipeline_url );
Expand Down
11 changes: 5 additions & 6 deletions t/10.pipeconfig/pipeline_url.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ use warnings;

use Test::More;

use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline beekeeper get_test_url_or_die safe_drop_database);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline get_test_url_or_die safe_drop_database);
use Bio::EnsEMBL::Hive::Utils qw(destringify);

# 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) ) ) );

my $pipeline_url = get_test_url_or_die();

# Utils::Test::init_pipeline runs things internally instead of invoking init_pipeline.pl
# Here we need to run the script to trigger the password sanitization
my @cmd = ('env', 'PERL5LIB='.$ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB}, $ENV{'EHIVE_ROOT_DIR'}.'/scripts/init_pipeline.pl', 'TestPipeConfig::PipelineURL_conf', -pipeline_url => $pipeline_url);
my $rc = system(@cmd);
is($rc, 0, 'init_pipeline.pl successfully ran');
{
local $ENV{'PERL5LIB'} = $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB};
init_pipeline('TestPipeConfig::PipelineURL_conf', $pipeline_url);
}

my $hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new( -url => $pipeline_url );

Expand Down

0 comments on commit e6e1390

Please sign in to comment.