blib/lib/App/TestOnTap/ParallelGroupManager.pm

filter: Statementstmt 56.3% 31 / 55 Branchbran 12.5% 2 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 50.0% 40 / 80 SCAR 35.3
CC
12
Cov
46%
__parseParallelGroups
41.6
cull
10.2
BEGIN
1.0
CRAP 34.1
« blib/lib/App/TestOnTap/Dispenser.pm ↑ Summary blib/lib/App/TestOnTap/Config.pm »
1 package App::TestOnTap::ParallelGroupManager;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use Grep::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use List::MoreUtils qw(singleton);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # CTOR
10 #
11 sub new
12 {
13 27 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 27 my $cfg = shift;
15  
16 27 my $self = bless( {}, $class);
17 27 $self->__parseParallelGroups($cfg);
18
19 27 return $self;
20 }
21  
22 sub cull
23 {
24 55 ▶ my $self = shift;
Subroutine cull: called CC=5 SCAR=23.2
Pod undocumented
25 55 my $inprogress = shift;
26 55 my $eligible = shift;
27  
28 55 ▶ return () unless @$eligible;
Branch: 1 branch
BranchTrueFalseTotal
unless @$eligible 53 2 55
29
30 2 foreach my $pgname (sort(keys(%{$self->{pargroups}})))
31 {
32 0 my $matcher = $self->{pargroups}->{$pgname}->{match};
33 0 my $maxconcurrent = $self->{pargroups}->{$pgname}->{maxconcurrent};
34
35 0 my @matchingInprogress = $matcher->qgrep(@$inprogress);
36 0 my @matchingEligible = $matcher->qgrep(@$eligible);
37  
38 0 my @allmatching = (@matchingInprogress, @matchingEligible);
39 0 my $leave = scalar(@allmatching) - $maxconcurrent;
40 0 ▶ $leave = 0 if $leave < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $leave < 0 0 0 0
41 0 ▶ shift(@allmatching) while (@allmatching > $leave);
Branch: 1 branch
BranchTrueFalseTotal
@allmatching > $leave and do { shift @allmatching } 0 0 0
42 0 @$eligible = singleton(@allmatching, @$eligible);
43 }
44
45 2 return @$eligible;
46 }
47  
48 sub __parseParallelGroups
49 {
50 27 ▶ my $self = shift;
Subroutine __parseParallelGroups: called CC=8 SCAR=37.3
51 27 my $cfg = shift;
52  
53 27 my %parGroups;
54 # find all parallelgroup sections
55 #
56 27 my $pgRx = qr(^\s*PARALLELGROUP\s+(.+?)\s*$);
57 27 foreach my $pgRuleSectionName (grep(/$pgRx/, keys(%$cfg)))
58 {
59 0 $pgRuleSectionName =~ /$pgRx/;
60 0 my $pgRuleName = $1;
61
62 # all pg sections requires 'match' Grep::Query queries
63 # in case match is written as array, just join using newlines
64 #
65 0 my $match = $cfg->{$pgRuleSectionName}->{match};
66 0 ▶ die("Missing key 'match' in parallel group rule section '$pgRuleName'\n") unless defined($match);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $match 0 0 0
67 0 ▶ $match = join("\n", @$match) if ref($match) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $match eq "ARRAY" 0 0 0
68 0 $parGroups{$pgRuleName}->{match} = Grep::Query->new($match);
69  
70 # all pg sections requires 'maxconcurrent' positive integer values
71 #
72 0 my $maxconcurrent = $cfg->{$pgRuleSectionName}->{maxconcurrent};
73 0 ▶ die("Missing key 'maxconcurrent' in parallel group rule section '$pgRuleName'\n") unless defined($maxconcurrent);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $maxconcurrent 0 0 0
74 0 ▶ die("Illegal value for 'maxconcurrent' in parallel group rule section '$pgRuleName'\n") unless $maxconcurrent > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $maxconcurrent > 1 0 0 0
75 0 $parGroups{$pgRuleName}->{maxconcurrent} = $maxconcurrent;
76
77 # check for unknown keys...
78 #
79 0 my %validSectionKeys = map { $_ => 1 } qw(match maxconcurrent);
80 0 foreach my $key (keys(%{$cfg->{$pgRuleSectionName}}))
81 {
82 0 ▶ warn("WARNING: Unknown key '$key' in section '[$pgRuleSectionName]'\n") unless exists($validSectionKeys{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $validSectionKeys{$key} 0 0 0
83 }
84 }
85 27 $self->{pargroups} = \%parGroups;
86 }
87  
88 19 1;
« blib/lib/App/TestOnTap/Dispenser.pm ↑ Summary blib/lib/App/TestOnTap/Config.pm »