« blib/lib/App/Prove/Elasticsearch/Searcher/ByName.pm
↑ Summary
blib/lib/App/Prove/Elasticsearch/Utils.pm »
| 1 | package App::Prove::Elasticsearch::Queue::Default; | ||||||||||||||||||||||||||||
| 2 | 4 | $App::Prove::Elasticsearch::Queue::Default::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # PODNAME: App::Prove::Elasticsearch::Queue::Default; | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Coordinate the running of test plans across multiple forks. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use List::Util 1.45 qw{shuffle uniq}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use App::Prove::Elasticsearch::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 1 | my ($class, $input) = @_; | |||||||||||||||||||||||||||
| 15 | 1 | my $conf = App::Prove::Elasticsearch::Utils::process_configuration($input); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | my $planner = App::Prove::Elasticsearch::Utils::require_planner($conf); | |||||||||||||||||||||||||||
| 18 | 1 | &{\&{$planner . "::check_index"}}($conf); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | return bless({config => $conf, planner => $planner}, $class); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | sub get_jobs { | ||||||||||||||||||||||||||
|
Subroutine
get_jobs: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 3 | my ($self, $jobspec) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | $self->_get_searcher(); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | $jobspec->{searcher} = $self->{searcher}; | |||||||||||||||||||||||||||
| 29 | 3 | my $plans = &{\&{$self->{planner} . "::get_plans_needing_work"}}(%$jobspec); | |||||||||||||||||||||||||||
| 30 | 3 | ▶ | return () unless scalar(@$plans); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | my @tests; | |||||||||||||||||||||||||||
| 33 | 2 | foreach my $plan (@$plans) { | |||||||||||||||||||||||||||
| 34 | my @tmp_tests = | ||||||||||||||||||||||||||||
| 35 | 4 | ▶ | ref $plan->{tests} eq 'ARRAY' ? @{$plan->{tests}} : ($plan->{tests}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 4 | push(@tests, @tmp_tests); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 2 | @tests = shuffle($self->{searcher}->filter(uniq @tests)); | |||||||||||||||||||||||||||
| 39 | 2 | ▶ | return @tests unless $self->{config}->{'queue.granularity'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | @tests = splice(@tests, 0, $self->{config}->{'queue.granularity'}); | |||||||||||||||||||||||||||
| 41 | 1 | return @tests; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | sub _get_indexer { | ||||||||||||||||||||||||||
|
Subroutine
_get_indexer: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 45 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | $self->{indexer} //= | ||||||||||||||||||||||||||||
| 47 | 2 | ▶ | App::Prove::Elasticsearch::Utils::require_indexer($self->{config}); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"indexer"} //= App::Prove::Elasticsearch::Utils::require_indexer($self->{"config"})
MC/DC0%0/2
$self->{"indexer"} //= App::Prove::Elasticsearch::Utils::require_indexer($self->{"config"})
$self->{"indexer"}
App::Prove::Elasticsearch::Utils::require_indexer($self->{"config"})
Truth table66%2/3
A //= B
A= $self->{"indexer"}B= App::Prove::Elasticsearch::Utils::require_indexer($self->{"config"})
| |||||||||||||||||||||||||||||
| 48 | 2 | return $self->{indexer}; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | sub _get_searcher { | ||||||||||||||||||||||||||
|
Subroutine
_get_searcher: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 52 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 2 | ▶ | return $self->{searcher} if $self->{searcher}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | my $searcher = | ||||||||||||||||||||||||||||
| 55 | 1 | App::Prove::Elasticsearch::Utils::require_searcher($self->{config}); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | $self->{searcher} = &{\&{$searcher . "::new"}} | |||||||||||||||||||||||||||
| 58 | 1 | ($searcher, $self->{config}, $self->_get_indexer()); | |||||||||||||||||||||||||||
| 59 | 1 | return $self->{searcher}; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub list_queues { | ||||||||||||||||||||||||||
|
Subroutine
list_queues: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 2 | my ($self, %matrix) = @_; | |||||||||||||||||||||||||||
| 64 | 2 | my $pf = []; | |||||||||||||||||||||||||||
| 65 | 2 | @$pf = grep { defined $_ } values(%{$matrix{cur_platforms}}); | |||||||||||||||||||||||||||
| 66 | 2 | push(@$pf, @{$matrix{unsatisfiable_platforms}}); | |||||||||||||||||||||||||||
| 67 | my %jobspec = ( | ||||||||||||||||||||||||||||
| 68 | version => $matrix{cur_version}, | ||||||||||||||||||||||||||||
| 69 | 2 | platforms => $pf, | |||||||||||||||||||||||||||
| 70 | searcher => $self->_get_searcher(), | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | 2 | my $plans = &{\&{$self->{planner} . "::get_plans_needing_work"}}(%jobspec); | |||||||||||||||||||||||||||
| 73 | 2 | ▶ | return @$plans if @$plans; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #construct iterator | ||||||||||||||||||||||||||||
| 76 | my @pigeonholes = | ||||||||||||||||||||||||||||
| 77 | 2 | map { $matrix{platforms}{$_} } | |||||||||||||||||||||||||||
| 78 | 1 | grep { scalar(@{$matrix{platforms}{$_}}) } keys(%{$matrix{platforms}}); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | my @plots; | |||||||||||||||||||||||||||
| 81 | 1 | my @iterator = @{$pigeonholes[0]}; | |||||||||||||||||||||||||||
| 82 | 1 | ▶ | while (scalar(@iterator)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 6 | my $subj = shift @iterator; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | #Handle initial elements | ||||||||||||||||||||||||||||
| 86 | 6 | ▶ | $subj = [$subj] if ref $subj ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | #Break out of the loop if we have no more possibilities to exploit | ||||||||||||||||||||||||||||
| 89 | 6 | ▶ | if (scalar(@$subj) == scalar(@pigeonholes)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 4 | push(@plots, $subj); | |||||||||||||||||||||||||||
| 91 | 4 | next; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | #Keep pushing partials on to the end of the iterator, until we run out of categories to add | ||||||||||||||||||||||||||||
| 95 | 2 | foreach my $element (@{$pigeonholes[ scalar(@$subj) ]}) { | |||||||||||||||||||||||||||
| 96 | 4 | my @partial = @$subj; | |||||||||||||||||||||||||||
| 97 | 4 | push(@partial, $element); | |||||||||||||||||||||||||||
| 98 | 4 | push(@iterator, \@partial); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 1 | @plots = map { [ @$_, @{$matrix{'unsatisfiable_platforms'}} ] } @plots; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | #OK, now I have a list of potential platforms I can ask whether they exist | ||||||||||||||||||||||||||||
| 104 | 1 | foreach my $gambit (@plots) { | |||||||||||||||||||||||||||
| 105 | 1 | $jobspec{platforms} = $gambit; | |||||||||||||||||||||||||||
| 106 | 1 | $plans = &{\&{$self->{planner} . "::get_plans_needing_work"}}(%jobspec); | |||||||||||||||||||||||||||
| 107 | 1 | ▶ | return @$plans if (ref($plans) eq 'ARRAY') && @$plans; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $plans eq "ARRAY" and @$plans
MC/DC0%0/2
ref $plans eq "ARRAY" and @$plans
ref $plans eq "ARRAY"
@$plans
Truth table33%1/3
A and B
A= ref $plans eq "ARRAY"B= @$plans
| |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 0 | return (); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub queue_jobs { | ||||||||||||||||||||||||||
|
Subroutine
queue_jobs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 1 | print "Queued local job.\n"; | |||||||||||||||||||||||||||
| 114 | 1 | return 0; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | sub build_queue_name { | ||||||||||||||||||||||||||
|
Subroutine
build_queue_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 1 | my ($self, $jobspec) = @_; | |||||||||||||||||||||||||||
| 119 | 1 | my $name = $jobspec->{version}; | |||||||||||||||||||||||||||
| 120 | 1 | $name .= join('', @{$jobspec->{platforms}}); | |||||||||||||||||||||||||||
| 121 | 1 | return $name; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 4 | 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||