blib/lib/Test2/Workflow/Runner.pm

filter: Statementstmt 92.5% 249 / 269 Branchbran 78.3% 116 / 148 Conditioncond 55.9% 33 / 59 MC/DCmcdc 30.5% 11 / 36 Subroutinesub 100% 24 / 24 Podpod 0.0% 0 / 10 totaltotal 79.3% 433 / 546 CC 100 SCAR 33.7
CC
100
Cov
84%
run
54.3
init
28.3
isolate
20.2
CRAP 29.2
« blib/lib/Test2/Workflow/Task.pm ↑ Summary blib/lib/Test2/Tools/Spec.pm »
1 package Test2::Workflow::Runner;
2 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 36 our $VERSION = '1.302226';
6  
7 36 ▶use Test2::API();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 36 ▶use Test2::Todo();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 36 ▶use Test2::AsyncSubtest();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 36 ▶use Test2::Util qw/get_tid CAN_REALLY_FORK/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 36 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 36 ▶use Time::HiRes qw/sleep/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 36 ▶use List::Util qw/shuffle min/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 36 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 36 ▶use Test2::Util::HashBase qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
19 stack no_fork no_threads max slots pid tid rand subtests filter
20 36 };
21  
22 36 ▶use overload(
Subroutine BEGIN: called CC=1 SCAR=0.0
23 'fallback' => 1,
24 154 ▶ '&{}' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 154 my $self = shift;
26  
27 154 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 154 @_ = ($self);
29 154 goto &run;
30 }
31 154 },
32 36 );
33  
34 44 ▶sub init {
Subroutine init: called CC=15 SCAR=33.4
Pod undocumented
35 44 my $self = shift;
36  
37 44 $self->{+STACK} = [];
38 44 $self->{+SUBTESTS} = [];
39  
40 44 $self->{+PID} = $$;
41 44 $self->{+TID} = get_tid();
42  
43 44 ▶ $self->{+NO_FORK} ||= $ENV{T2_WORKFLOW_NO_FORK} || !CAN_REALLY_FORK();
Condition50%3/6
$self->{"no_fork"} ||= $ENV{"T2_WORKFLOW_NO_FORK"} || !&CAN_REALLY_FORK()
l!l&&r!l&&!r
2042
$ENV{'T2_WORKFLOW_NO_FORK'} || !&CAN_REALLY_FORK()
l!l&&r!l&&!r
0042
MC/DC0%0/3
$self->{"no_fork"} ||= $ENV{"T2_WORKFLOW_NO_FORK"} || !&CAN_REALLY_FORK()
$self->{"no_fork"} $ENV{'T2_WORKFLOW_NO_FORK'} !&CAN_REALLY_FORK()
Truth table0%0/4
A ||= B || not(C)
A= $self->{"no_fork"}B= $ENV{'T2_WORKFLOW_NO_FORK'}C= !&CAN_REALLY_FORK()
ABCresult
1XX1
01X1
0011
0000
44  
45 44 my $can_thread = Test2::AsyncSubtest->CAN_REALLY_THREAD();
46 44 ▶ my $should_thread = ($ENV{T2_WORKFLOW_USE_THREADS} || $ENV{T2_DO_THREAD_TESTS}) && !$ENV{T2_WORKFLOW_NO_THREADS};
Condition33%2/6
($ENV{'T2_WORKFLOW_USE_THREADS'} || $ENV{'T2_DO_THREAD_TESTS'}) && !$ENV{'T2_WORKFLOW_NO_THREADS'}
!ll&&!rl&&r
4400
$ENV{"T2_WORKFLOW_USE_THREADS"} or $ENV{"T2_DO_THREAD_TESTS"}
l!l&&r!l&&!r
0044
MC/DC0%0/3
($ENV{'T2_WORKFLOW_USE_THREADS'} || $ENV{'T2_DO_THREAD_TESTS'}) && !$ENV{'T2_WORKFLOW_NO_THREADS'}
$ENV{"T2_WORKFLOW_USE_THREADS"} $ENV{"T2_DO_THREAD_TESTS"} !$ENV{'T2_WORKFLOW_NO_THREADS'}
Truth table20%1/5
A or B && not(C)
A= $ENV{"T2_WORKFLOW_USE_THREADS"}B= $ENV{"T2_DO_THREAD_TESTS"}C= !$ENV{'T2_WORKFLOW_NO_THREADS'}
ABCresult
00X0
1X00
0100
1X11
0111
47 44 ▶ $self->{+NO_THREADS} ||= !($can_thread && $should_thread);
Condition50%3/6
$self->{"no_threads"} ||= !($can_thread && $should_thread)
l!l&&r!l&&!r
9350
$can_thread && $should_thread
!ll&&!rl&&r
3500
MC/DC0%0/3
$self->{"no_threads"} ||= !($can_thread && $should_thread)
$self->{"no_threads"} $can_thread $should_thread
Truth table0%0/4
A ||= not(B && C)
A= $self->{"no_threads"}B= $can_threadC= $should_thread
ABCresult
1XX1
00X1
0101
0110
48  
49 44 ▶ $self->{+RAND} = 1 unless defined $self->{+RAND};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"rand"} 34 10 44
50  
51 44 my @max = grep {defined $_} $self->{+MAX}, $ENV{T2_WORKFLOW_ASYNC};
52 44 ▶ my $max = @max ? min(@max) : 3;
Branch: 1 branch
BranchTrueFalseTotal
@max ? : 0 44 44
53 44 $self->{+MAX} = $max;
54 44 ▶ $self->{+SLOTS} = [] if $max;
Branch: 1 branch
BranchTrueFalseTotal
if $max 44 0 44
55  
56 44 ▶ unless(defined($self->{+FILTER})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"filter"}) 35 9 44
57 35 ▶ if (my $raw = $ENV{T2_WORKFLOW}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $raw = $ENV{"T2_WORKFLOW"}) 0 35 35
58 0 my ($file, $line, $name);
59 0 ▶ if ($raw =~ m/^(.*)\s+(\d+)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($raw =~ /^(.*)\s+(\d+)$/) { } 0 0 0
elsif ($raw =~ /^(\d+)$/) { } 0 0 0
60 0 ($file, $line) = ($1, $2);
61 }
62 elsif($raw =~ m/^(\d+)$/) {
63 0 $line = $1;
64 }
65 else {
66 0 $name = $raw;
67 }
68  
69 0 $self->{+FILTER} = {
70 file => $file,
71 line => $line,
72 name => $name,
73 };
74 }
75 }
76  
77 44 ▶ if (my $task = delete $self->{task}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $task = delete $self->{"task"}) 9 35 44
78 9 $self->push_task($task);
79 }
80 }
81  
82 250 ▶sub is_local {
Subroutine is_local: called CC=3 SCAR=11.0
Pod undocumented
83 250 my $self = shift;
84 250 ▶ return 0 unless $self->{+PID} == $$;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"pid"} == $$ 18 232 250
85 232 ▶ return 0 unless $self->{+TID} == get_tid();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"tid"} == 0 0 232 232
86 232 return 1;
87 }
88  
89 187 ▶sub send_event {
Subroutine send_event: called CC=2 SCAR=7.1
Pod undocumented
90 187 my $self = shift;
91 187 my ($type, %params) = @_;
92  
93 187 my $class;
94 187 ▶ if ($type =~ m/\+(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /\+(.*)$/) { } 0 187 187
95 0 $class = $1;
96 }
97 else {
98 187 $class = "Test2::Event::$type";
99 }
100  
101 187 my $hub = Test2::API::test2_stack()->top();
102  
103 187 my $e = $class->new(
104 trace => Test2::Util::Trace->new(
105 frame => [caller(0)],
106 buffered => $hub->buffered,
107 nested => $hub->nested,
108 hid => $hub->hid,
109 huuid => $hub->uuid,
110 #cid => $self->{+CID},
111 #uuid => $self->{+UUID},
112 ),
113  
114 %params,
115 );
116  
117 187 $hub->send($e);
118 }
119  
120 495 ▶sub current_subtest {
Subroutine current_subtest: called CC=4 SCAR=13.9
Pod undocumented
121 495 my $self = shift;
122 495 ▶ my $stack = $self->{+STACK} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $stack = $self->{"stack"} or return undef 495 0 495
123  
124 495 for my $state (reverse @$stack) {
125 961 ▶ next unless $state->{subtest};
Branch: 1 branch
BranchTrueFalseTotal
unless $state->{"subtest"} 525 436 961
126 436 return $state->{subtest};
127 }
128  
129 59 return undef;
130 }
131  
132 196 ▶sub run {
Subroutine run: called CC=49 SCAR=40.0
Pod undocumented
133 196 my $self = shift;
134  
135 196 my $stack = $self->stack;
136  
137 196 my $c = 0;
138 196 ▶ while (@$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack) 3164 20 3184
139 3164 $self->cull;
140  
141 3164 my $state = $stack->[-1];
142 3164 my $task = $state->{task};
143  
144 3164 ▶ unless($state->{started}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"started"}++) 885 2279 3164
145 885 my $skip = $task->skip;
146  
147 885 my $filter;
148 885 ▶ if (my $f = $self->{+FILTER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = $self->{"filter"}) 649 236 885
149 649 my $in_var = grep { $_->{filter_satisfied} } @$stack;
150  
151 649 ▶ $filter = $task->filter($f) unless $in_var;
Branch: 1 branch
BranchTrueFalseTotal
unless $in_var 233 416 649
152 649 ▶ $state->{filter_satisfied} = 1 if $filter->{satisfied};
Branch: 1 branch
BranchTrueFalseTotal
if $filter->{"satisfied"} 25 624 649
153 }
154  
155 885 ▶ $skip ||= $filter->{skip} if $filter;
Branch: 1 branch
BranchTrueFalseTotal
if $filter 649 236 885
Condition66%2/3
$skip ||= $filter->{"skip"}
l!l&&r!l&&!r
0101548
MC/DC50%1/2
$skip ||= $filter->{"skip"}
$skip $filter->{"skip"}
Truth table66%2/3
A ||= B
A= $skipB= $filter->{"skip"}
ABresult
1X1
011
000
156  
157 885 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 101 784 885
158 101 $state->{ended}++;
159 101 ▶ $self->send_event(
Condition33%1/3
$skip || $filter
l!l&&r!l&&!r
10100
MC/DC0%0/2
$skip || $filter
$skip $filter
Truth table33%1/3
A || B
A= $skipB= $filter
ABresult
1X1
011
000
160 'Skip',
161 reason => $skip || $filter,
162 name => $task->name,
163 pass => 1,
164 effective_pass => 1,
165 );
166 101 pop @$stack;
167 101 next;
168 }
169  
170 784 ▶ if ($task->flat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($task->flat) { } 495 289 784
171 495 my $st = $self->current_subtest;
172 495 ▶ my $hub = $st ? $st->hub : Test2::API::test2_stack->top;
Branch: 1 branch
BranchTrueFalseTotal
$st ? : 436 59 495
173  
174 495 ▶ $state->{todo} = Test2::Todo->new(reason => $task->todo, hub => $hub)
Branch: 1 branch
BranchTrueFalseTotal
if $task->todo 0 495 495
175 if $task->todo;
176  
177 495 $hub->send($_) for @{$task->events};
178 }
179 else {
180 289 my $st = Test2::AsyncSubtest->new(
181 name => $task->name,
182 frame => $task->frame,
183 );
184 289 $state->{subtest} = $st;
185  
186 289 ▶ $state->{todo} = Test2::Todo->new(reason => $task->todo, hub => $st->hub)
Branch: 1 branch
BranchTrueFalseTotal
if $task->todo 0 289 289
187 if $task->todo;
188  
189 289 for my $e (@{$task->events}) {
190 1 my $hub = $st->hub;
191  
192 1 $e->trace->{buffered} = $hub->buffered;
193 1 $e->trace->{nested} = $hub->nested;
194 1 $e->trace->{hid} = $hub->hid;
195 1 $e->trace->{huuid} = $hub->uuid;
196  
197 1 $hub->send($e);
198 }
199  
200 289 my $slot = $self->isolate($state);
201  
202 # if we forked/threaded then this state has ended here.
203 289 ▶ if (defined($slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $slot) 100 189 289
204 100 ▶ push @{$self->{+SUBTESTS}} => [$st, $task] unless $st->finished;
Branch: 1 branch
BranchTrueFalseTotal
unless $st->finished 80 20 100
205 100 $state->{subtest} = undef;
206 100 $state->{ended} = 1;
207 }
208 }
209 }
210  
211 3063 ▶ if ($state->{ended}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"ended"}) 749 2314 3063
212 749 ▶ $state->{todo}->end() if $state->{todo};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"todo"} 0 749 749
213 749 ▶ $state->{subtest}->stop() if $state->{subtest};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"subtest"} 176 573 749
214  
215 749 ▶ return if $state->{in_thread};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"in_thread"} 0 749 749
216 749 ▶ if(my $guard = delete $state->{in_fork}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $guard = delete $state->{"in_fork"}) 22 727 749
217 22 $state->{subtest}->detach;
218 22 $guard->dismiss;
219 22 exit 0;
220 }
221  
222 727 pop @$stack;
223 727 next;
224 }
225  
226 2314 ▶ if($state->{subtest} && !$state->{subtest_started}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"subtest"} and not $state->{"subtest_started"}++) 189 2125 2314
Condition100%3/3
$state->{"subtest"} and not $state->{"subtest_started"}++
!ll&&!rl&&r
7601365189
MC/DC100%2/2
$state->{"subtest"} and not $state->{"subtest_started"}++
$state->{"subtest"} not $state->{"subtest_started"}++
Truth table100%3/3
A and not(B)
A= $state->{"subtest"}B= not $state->{"subtest_started"}++
ABresult
0X0
100
111
227 189 push @{$self->{+SUBTESTS}} => [$state->{subtest}, $task];
228 189 $state->{subtest}->start();
229 }
230  
231 2314 ▶ if ($task->isa('Test2::Workflow::Task::Action')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($task->isa("Test2::Workflow::Task::Action")) 481 1833 2314
232 481 $state->{PID} = $$;
233 481 my $ok = eval { $task->code->($self); 1 };
234  
235 481 ▶ unless ($state->{PID} == $$) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"PID"} == $$) 0 481 481
236 0 print STDERR "Task '" . $task->name . "' started in pid $state->{PID}, but ended in pid $$, did you forget to exit after forking?\n";
237 0 exit 255;
238 }
239  
240 481 ▶ $task->exception($@) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 481 481
241 481 $state->{ended} = 1;
242  
243 481 next;
244 }
245  
246 1833 ▶ if (!$state->{stage} || $state->{stage} eq 'BEFORE') {
Branch: 4 branches
BranchTrueFalseTotal
if (not $state->{'stage'} or $state->{'stage'} eq 'BEFORE') { } 515 1318 1833
elsif ($state->{'stage'} eq 'VARIANT') { } 203 1115 1318
elsif ($state->{'stage'} eq 'PRIMARY') { } 641 474 1115
elsif ($state->{'stage'} eq 'AFTER') { } 474 0 474
Condition66%2/3
not $state->{"stage"} or $state->{"stage"} eq "BEFORE"
l!l&&r!l&&!r
51501318
MC/DC50%1/2
not $state->{"stage"} or $state->{"stage"} eq "BEFORE"
not $state->{"stage"} $state->{"stage"} eq "BEFORE"
Truth table66%2/3
not(A) or B
A= not $state->{"stage"}B= $state->{"stage"} eq "BEFORE"
ABresult
1X1
011
000
247 515 ▶ $state->{before} = (defined $state->{before}) ? $state->{before} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $state->{'before'} ? : 312 203 515
248  
249 515 ▶ if (my $add = $task->before->[$state->{before}++]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $add = $task->before->[$state->{'before'}++]) { } 312 203 515
250 312 ▶ if ($add->around) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add->around) { } 154 158 312
251 154 $state->{PID} = $$;
252 154 my $ok = eval { $add->code->($self); 1 };
253 154 my $err = $@;
254 154 ▶ my $complete = $state->{stage} && $state->{stage} eq 'AFTER';
Condition33%1/3
$state->{'stage'} && $state->{'stage'} eq 'AFTER'
!ll&&!rl&&r
00154
MC/DC0%0/2
$state->{'stage'} && $state->{'stage'} eq 'AFTER'
$state->{'stage'} $state->{'stage'} eq 'AFTER'
Truth table33%1/3
A && B
A= $state->{'stage'}B= $state->{'stage'} eq 'AFTER'
ABresult
0X0
100
111
255  
256 154 ▶ unless ($state->{PID} == $$) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"PID"} == $$) 0 154 154
257 0 print STDERR "Task '" . $task->name . "' started in pid $state->{PID}, but ended in pid $$, did you forget to exit after forking?\n";
258 0 exit 255;
259 }
260  
261 154 ▶ unless($ok && $complete) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok and $complete) 0 154 154
Condition33%1/3
$ok and $complete
!ll&&!rl&&r
00154
MC/DC0%0/2
$ok and $complete
$ok $complete
Truth table33%1/3
A and B
A= $okB= $complete
ABresult
0X0
100
111
262 0 $state->{ended} = 1;
263 0 $state->{stage} = 'AFTER';
264 0 ▶ $task->exception($ok ? "'around' task failed to continue into the workflow chain.\n" : $err);
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
265 }
266 }
267 else {
268 158 $self->push_task($add);
269 }
270 }
271 else {
272 203 $state->{stage} = 'VARIANT';
273 }
274 }
275 elsif ($state->{stage} eq 'VARIANT') {
276 203 ▶ if (my $v = $task->variant) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $v = $task->variant) 60 143 203
277 60 $self->push_task($v);
278 }
279 203 $state->{stage} = 'PRIMARY';
280 }
281 elsif ($state->{stage} eq 'PRIMARY') {
282 641 ▶ unless (defined $state->{order}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $state->{"order"}) 203 438 641
283 203 ▶ my $rand = defined($task->rand) ? $task->rand : $self->rand;
Branch: 1 branch
BranchTrueFalseTotal
defined $task->rand ? : 0 203 203
284 203 $state->{order} = [0 .. scalar(@{$task->primary}) - 1];
285 203 ▶ @{$state->{order}} = shuffle(@{$state->{order}})
Branch: 1 branch
BranchTrueFalseTotal
if $rand 60 143 203
286 if $rand;
287 }
288 641 my $num = shift @{$state->{order}};
289 641 ▶ if (defined $num) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $num) { } 473 168 641
290 473 $self->push_task($task->primary->[$num]);
291 }
292 else {
293 168 $state->{stage} = 'AFTER';
294 }
295 }
296 elsif ($state->{stage} eq 'AFTER') {
297 474 ▶ $state->{after} = (defined $state->{after}) ? $state->{after} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $state->{'after'} ? : 306 168 474
298 474 ▶ if (my $add = $task->after->[$state->{after}++]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $add = $task->after->[$state->{'after'}++]) { } 306 168 474
299 306 ▶ return if $add->around;
Branch: 1 branch
BranchTrueFalseTotal
if $add->around 154 152 306
300 152 $self->push_task($add);
301 }
302 else {
303 168 $state->{ended} = 1;
304 }
305 }
306 }
307  
308 20 $self->finish;
309 }
310  
311 885 ▶sub push_task {
Subroutine push_task: called CC=6 SCAR=18.7
Pod undocumented
312 885 my $self = shift;
313 885 my ($task) = @_;
314  
315 885 ▶ confess "No Task!" unless $task;
Branch: 1 branch
BranchTrueFalseTotal
unless $task 0 885 885
316 885 ▶ confess "Bad Task ($task)!" unless blessed($task) && $task->isa('Test2::Workflow::Task');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($task) and $task->isa("Test2::Workflow::Task") 0 885 885
Condition33%1/3
builtin::blessed($task) and $task->isa("Test2::Workflow::Task")
!ll&&!rl&&r
00885
MC/DC0%0/2
builtin::blessed($task) and $task->isa("Test2::Workflow::Task")
builtin::blessed($task) $task->isa("Test2::Workflow::Task")
Truth table33%1/3
A and B
A= builtin::blessed($task)B= $task->isa("Test2::Workflow::Task")
ABresult
0X0
100
111
317  
318 885 ▶ if ($task->isa('Test2::Workflow::Build')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($task->isa("Test2::Workflow::Build")) 9 876 885
319 confess "Can only push a Build instance when initializing the stack"
320 9 ▶ if @{$self->{+STACK}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"stack"};} 0 9 9
321 9 $task = $task->compile();
322 }
323  
324 885 push @{$self->{+STACK}} => {
325 task => $task,
326 name => $task->name,
327 };
328 }
329  
330 8 ▶sub add_mock {
Subroutine add_mock: called CC=3 SCAR=11.3
Pod undocumented
331 8 my $self = shift;
332 8 my ($mock) = @_;
333 8 my $stack = $self->{+STACK};
334  
335 8 ▶ confess "Nothing on the stack!"
Branch: 1 branch
BranchTrueFalseTotal
unless $stack and @$stack 0 8 8
Condition33%1/3
$stack and @$stack
!ll&&!rl&&r
008
MC/DC0%0/2
$stack and @$stack
$stack @$stack
Truth table33%1/3
A and B
A= $stackB= @$stack
ABresult
0X0
100
111
336 unless $stack && @$stack;
337  
338 8 my ($state) = grep { !$_->{task}->scaffold} reverse @$stack;
339 8 push @{$state->{mocks}} => $mock;
340 }
341  
342 289 ▶sub isolate {
Subroutine isolate: called CC=18 SCAR=30.1
Pod undocumented
343 289 my $self = shift;
344 289 my ($state) = @_;
345  
346 289 ▶ return if $state->{task}->skip;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"task"}->skip 0 289 289
347  
348 289 my $iso = $state->{task}->iso;
349 289 my $async = $state->{task}->async;
350  
351 # No need to isolate
352 289 ▶ return undef unless $iso || $async;
Branch: 1 branch
BranchTrueFalseTotal
unless $iso or $async 164 125 289
Condition66%2/3
$iso or $async
l!l&&r!l&&!r
1250164
MC/DC50%1/2
$iso or $async
$iso $async
Truth table66%2/3
A or B
A= $isoB= $async
ABresult
1X1
011
000
353  
354 # Cannot isolate
355 125 ▶ unless($self->{+MAX} && $self->is_local) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"max"} and $self->is_local) 9 116 125
Condition66%2/3
$self->{"max"} and $self->is_local
!ll&&!rl&&r
09116
MC/DC50%1/2
$self->{"max"} and $self->is_local
$self->{"max"} $self->is_local
Truth table66%2/3
A and B
A= $self->{"max"}B= $self->is_local
ABresult
0X0
100
111
356 # async does not NEED to be isolated
357 9 ▶ return undef unless $iso;
Branch: 1 branch
BranchTrueFalseTotal
unless $iso 0 9 9
358 }
359  
360 # Wait for a slot, if max is set to 0 then we will not find a slot, instead
361 # we use '0'. We need to return a defined value to let the stack know that
362 # the task has ended.
363 125 my $slot = 0;
364 125 ▶ while($self->{+MAX} && $self->is_local) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max"} and $self->is_local) 116 9 125
Condition66%2/3
$self->{"max"} and $self->is_local
!ll&&!rl&&r
09116
MC/DC50%1/2
$self->{"max"} and $self->is_local
$self->{"max"} $self->is_local
Truth table66%2/3
A and B
A= $self->{"max"}B= $self->is_local
ABresult
0X0
100
111
365 116 $self->cull;
366 116 for my $s (1 .. $self->{+MAX}) {
367 171 my $st = $self->{+SLOTS}->[$s];
368 171 ▶ next if $st && !$st->finished;
Branch: 1 branch
BranchTrueFalseTotal
if $st and not $st->finished 55 116 171
Condition100%3/3
$st and not $st->finished
!ll&&!rl&&r
674955
MC/DC100%2/2
$st and not $st->finished
$st not $st->finished
Truth table100%3/3
A and not(B)
A= $stB= not $st->finished
ABresult
0X0
100
111
369 116 $self->{+SLOTS}->[$s] = undef;
370 116 $slot = $s;
371 116 last;
372 }
373 116 ▶ last if $slot;
Branch: 1 branch
BranchTrueFalseTotal
if $slot 116 0 116
374 0 sleep(0.02);
375 }
376  
377 my $st = $state->{subtest}
378 125 ▶ or confess "Cannot isolate a task without a subtest";
Branch: 1 branch
BranchTrueFalseTotal
my $st = $state->{"subtest"} or confess("Cannot isolate a task without a subtest") 125 0 125
379  
380 125 ▶ if (!$self->no_fork) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->no_fork) { } 111 14 125
elsif (not $self->no_threads) { } 0 14 14
381 111 my $out = $st->fork;
382 111 ▶ if (blessed($out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($out)) { } 25 86 111
383 25 $state->{in_fork} = $out;
384  
385 # drop back out to complete the task.
386 25 return undef;
387 }
388 else {
389 $self->send_event(
390 'Note',
391 message => "Forked PID $out to run: " . $state->{task}->name,
392 86 );
393 86 $state->{pid} = $out;
394 }
395 }
396 elsif (!$self->no_threads) {
397 0 $state->{in_thread} = 1;
398 0 my $thr = $st->run_thread(\&run, $self);
399 0 $state->{thread} = $thr;
400 0 delete $state->{in_thread};
401 $self->send_event(
402 'Note',
403 message => "Started Thread-ID " . $thr->tid . " to run: " . $state->{task}->name,
404 0 );
405 }
406 else {
407 14 $st->finish(skip => "No isolation method available");
408 14 return 0;
409 }
410  
411 86 ▶ if($slot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slot) { } 80 6 86
412 80 $self->{+SLOTS}->[$slot] = $st;
413 }
414 else {
415 6 $st->finish;
416 }
417  
418 86 return $slot;
419 }
420  
421 3656 ▶sub cull {
Subroutine cull: called CC=6 SCAR=18.0
Pod undocumented
422 3656 my $self = shift;
423  
424 3656 ▶ my $subtests = delete $self->{+SUBTESTS} || return;
Condition50%1/2
delete $self->{'subtests'} || (return)
l!l
36560
MC/DC0%0/1
delete $self->{'subtests'} || (return)
delete $self->{'subtests'}
Truth table50%1/2
A
A= delete $self->{'subtests'}
Aresult
11
00
425 3656 my @new;
426  
427 # Cull subtests in reverse order, Nested subtests end before their parents.
428 3656 for my $set (reverse @$subtests) {
429 9451 my ($st, $task) = @$set;
430 9451 ▶ next if $st->finished;
Branch: 1 branch
BranchTrueFalseTotal
if $st->finished 0 9451 9451
431 9451 ▶ if (!$st->active && $st->ready) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $st->active and $st->ready) 213 9238 9451
Condition100%3/3
not $st->active and $st->ready
!ll&&!rl&&r
81241114213
MC/DC100%2/2
not $st->active and $st->ready
not $st->active $st->ready
Truth table100%3/3
not(A) and B
A= not $st->activeB= $st->ready
ABresult
0X0
100
111
432 213 $st->finish();
433 213 next;
434 }
435  
436 # Use unshift to preserve order.
437 9238 unshift @new => $set;
438 }
439  
440 3656 $self->{+SUBTESTS} = \@new;
441  
442 3656 return;
443 }
444  
445 20 ▶sub finish {
Subroutine finish: called CC=3 SCAR=11.0
Pod undocumented
446 20 my $self = shift;
447 20 ▶ while(@{$self->{+SUBTESTS}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"subtests"};}) 376 20 396
448 376 $self->cull;
449 376 ▶ sleep(0.02) if @{$self->{+SUBTESTS}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"subtests"};} 373 3 376
450 }
451 }
452  
453 36 1;
454  
455 __END__
« blib/lib/Test2/Workflow/Task.pm ↑ Summary blib/lib/Test2/Tools/Spec.pm »