blib/lib/App/TestOnTap/Scheduler.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 6 / 6 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 93.3% 70 / 75 SCAR 19.5
CC
7
Cov
98%
get_job
6.0
new
2.0
BEGIN
1.0
CRAP 7.0
« blib/lib/App/TestOnTap/OrderStrategy.pm ↑ Summary blib/lib/App/TestOnTap.pm »
1 package App::TestOnTap::Scheduler;
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 TAP::Parser::Scheduler::Job;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use TAP::Parser::Scheduler::Spinner;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # This acts like a TAP Scheduler, but uses the test dispenser
10 # to give out jobs.
11 # This happens according to eligibility after continually
12 # toposorting and removing completed jobs, making
13 # it possible to parallelize tests efficiently
14 #
15 sub new
16 {
17 26 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
18 26 my $dispenser = shift;
19 26 my @testPairs = @_;
20  
21 # create
22 #
23 26 my $self = bless
24 (
25 {
26 pez => $dispenser,
27 jobs => undef,
28 queue => undef,
29 finished => [],
30 spinner => TAP::Parser::Scheduler::Spinner->new()
31 },
32 $class
33 );
34  
35 # create a list of job objects which is what
36 # the harness wants
37 # also hook them up to a closure to be called when they finish
38 #
39 26 my %jobs;
40 26 foreach my $pair (@testPairs)
41 {
42 48 my $job = TAP::Parser::Scheduler::Job->new(@$pair);
43 48 ▶ $job->on_finish( sub { $self->__finish(@_) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
44 48 $jobs{$job->description()} = $job;
45 }
46 26 $self->{jobs} = \%jobs;
47
48 26 return $self;
49 }
50  
51 # list of all remaining tests (jobs)
52 #
53 sub get_all
54 {
55 25 ▶ my $self = shift;
Subroutine get_all: called CC=1 SCAR=0.0
Pod undocumented
56  
57 25 return values(%{$self->{jobs}});
58 }
59  
60 # return the next eligible job
61 # - if all jobs completed, return undef
62 # - if no job is currently eligible (due to dependencies etc), return a 'spinner' job
63 #
64 sub get_job
65 {
66 85 ▶ my $self = shift;
Subroutine get_job: called CC=6 SCAR=17.9
Pod undocumented
67  
68 # maintain a queue of eligible tests here since we should deliver just one job
69 # at a time but the dispenser may 'free up' multiple at a time
70 #
71 85 ▶ if (!$self->{queue} || ($self->{queue} && !@{$self->{queue}}))
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"queue"} or $self->{"queue"} and not @{$self->{"queue"};}) 81 4 85
Condition83%5/6
not $self->{"queue"} or $self->{"queue"} and not @{$self->{"queue"};}
l!l&&r!l&&!r
26554
$self->{"queue"} and not @{$self->{"queue"};}
!ll&&!rl&&r
0455
MC/DC66%2/3
not $self->{"queue"} or $self->{"queue"} and not @{$self->{"queue"};}
not $self->{"queue"} $self->{"queue"} not @{$self->{"queue"};}
Truth table75%3/4
not(A) or B and not(C)
A= not $self->{"queue"}B= $self->{"queue"}C= not @{$self->{"queue"};}
ABCresult
1XX1
0111
00X0
0100
72 {
73 # if there is no queue right now (first call after creation)
74 # or the queue is empty, attempt to retrieve a new queue from the
75 # dispenser. The dispenser is called with the current list of finished
76 # jobs, so it may recompute and see what, if anything, is now free to run
77 #
78 81 $self->{queue} = $self->{pez}->getEligibleTests($self->{finished});
79 81 $self->{finished} = [];
80 }
81
82 # the dispenser will return undef when there are no more tests, which means we
83 # will return undef too
84 #
85 85 my $job;
86 85 ▶ if ($self->{queue})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"queue"}) 59 26 85
87 {
88 59 ▶ if (@{$self->{queue}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'queue'};}) { } 48 11 59
89 {
90 # if there are tests in the queue, pop the first
91 # and translate it to a job object
92 #
93 48 my $t = shift(@{$self->{queue}});
94 48 $job = $self->{jobs}->{$t};
95 }
96 else
97 {
98 # the queue is empty but still active, so spin our wheels a bit...
99 #
100 11 $job = $self->{spinner};
101 }
102 }
103  
104 85 return $job;
105 }
106  
107 sub __finish
108 {
109 48 ▶ my $self = shift;
Subroutine __finish: called CC=1 SCAR=0.0
110 48 my $job = shift;
111
112 48 my $t = $job->description();
113 48 push(@{$self->{finished}}, $t);
114 48 delete($self->{jobs}->{$t});
115 }
116  
117 19 1;
« blib/lib/App/TestOnTap/OrderStrategy.pm ↑ Summary blib/lib/App/TestOnTap.pm »