SmokeBox/Backend.pm

filter: Statementstmt 81.7% 246 / 301 Branchbran 60.2% 94 / 156 Conditioncond 36.6% 22 / 60 MC/DCmcdc 2.5% 1 / 39 Subroutinesub 86.1% 31 / 36 Podpod 100% 7 / 7 totaltotal 66.9% 401 / 599 CC 103 SCAR 27.8
CC
103
Cov
70%
spawn
35.9
_wheel_kill
33.0
_detect_loop
27.8
CRAP 16.2
↑ Summary SmokeBox/JobQueue.pm »
1 package POE::Component::SmokeBox::Backend;
2 47 $POE::Component::SmokeBox::Backend::VERSION = '0.54';
3 #ABSTRACT: smoker backend to POE::Component::SmokeBox
4  
5 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 47 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 47 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 47 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 47 ▶use File::Path qw[rmtree];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 47 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 47 ▶use POSIX qw( O_CREAT O_RDWR O_RDONLY ); # for SDBM_File
Subroutine BEGIN: called CC=1 SCAR=0.0
13 47 ▶use SDBM_File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 47 ▶use POE qw[Wheel::Run Filter::Line];
Subroutine BEGIN: called CC=1 SCAR=0.0
15 47 ▶use Digest::SHA qw[sha256_hex];
Subroutine BEGIN: called CC=1 SCAR=0.0
16 47 ▶use Env::Sanctify;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 47 ▶use Module::Pluggable search_path => 'POE::Component::SmokeBox::Backend', sub_name => 'backends', except => 'POE::Component::SmokeBox::Backend::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 47 my $GOT_KILLFAM;
20 my $GOT_PTY;
21  
22 BEGIN {
23 47 ▶ $GOT_KILLFAM = 0;
Subroutine BEGIN: called CC=3 SCAR=15.0
24 47 eval {
25 47 require Proc::ProcessTable;
26 0 $GOT_KILLFAM = 1;
27 };
28 47 $GOT_PTY = 0;
29 47 eval {
30 47 require IO::Pty;
31 47 $GOT_PTY = 1;
32 };
33 47 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 47 47
34 0 require POE::Wheel::Run::Win32;
35  
36 # MSWin32: Disable critical error popups
37 # Thanks to https://rt.cpan.org/Public/Bug/Display.html?id=56547
38  
39 # Call kernel32.SetErrorMode(SEM_FAILCRITICALERRORS):
40 # "The system does not display the critical-error-handler message box.
41 # Instead, the system sends the error to the calling process." and
42 # "A child process inherits the error mode of its parent process."
43 0 ▶ if ( eval { require Win32API::File } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Win32API::File } }) { } 0 0 0
44 0 Win32API::File->import( qw( SetErrorMode SEM_FAILCRITICALERRORS SEM_NOGPFAULTERRORBOX ) );
45 0 SetErrorMode( SEM_FAILCRITICALERRORS() | SEM_NOGPFAULTERRORBOX() );
46 } else {
47 0 warn "Unable to use Win32API::File -> $@";
48 0 warn 'This means sometimes perl.exe will popup a dialog box... Annoying!';
49 }
50 }
51 }
52  
53 47 my @cmds = qw(check index smoke);
54  
55 sub check {
56 7 ▶ my $package = shift;
Subroutine check: called CC=1 SCAR=0.0
Pod documented
57 7 return $package->spawn( @_, command => 'check' );
58 }
59  
60 sub index {
61 5 ▶ my $package = shift;
Subroutine index: called CC=1 SCAR=0.0
Pod documented
62 5 return $package->spawn( @_, command => 'index' );
63 }
64  
65 sub smoke {
66 12 ▶ my $package = shift;
Subroutine smoke: called CC=1 SCAR=0.0
Pod documented
67 12 return $package->spawn( @_, command => 'smoke' );
68 }
69  
70 sub spawn {
71 108 ▶ my $package = shift;
Subroutine spawn: called CC=25 SCAR=35.8
Pod documented
72 108 my %opts = @_;
73 108 my $extra = { map { ( $_ => delete $opts{$_} ) } grep { /^\_/ } keys %opts };
74 108 $opts{extra} = $extra;
75 108 $opts{lc $_} = delete $opts{$_} for keys %opts;
76 108 my $options = delete $opts{options};
77 108 ▶ unless ( $opts{event} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"event"}) 0 108 108
78 0 carp "The 'event' parameter is a mandatory requirement\n";
79 0 return;
80 }
81 108 ▶ $opts{idle} = 600 unless $opts{idle};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"idle"} 22 86 108
82 108 ▶ $opts{timeout} = 3600 unless $opts{timeout};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"timeout"} 23 85 108
83 108 ▶ $opts{timer} = 60 unless $opts{timer};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"timer"} 106 2 108
84 108 ▶ $opts{reaper} = 30 unless $opts{reaper};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"reaper"} 108 0 108
85 108 ▶ $opts{type} = 'CPANPLUS::YACSmoke' unless $opts{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"type"} 4 104 108
86 108 ▶ $opts{command} = lc $opts{command} || 'check';
Condition50%1/2
lc $opts{'command'} || 'check'
l!l
1080
MC/DC0%0/1
lc $opts{'command'} || 'check'
lc $opts{'command'}
Truth table50%1/2
A
A= lc $opts{'command'}
Aresult
11
00
87 108 ▶ $opts{command} = 'check' unless grep { $_ eq $opts{command} } @cmds;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $opts{"command"};} @cmds 0 108 108
88 108 ▶ $opts{perl} = $^X unless $opts{perl}; # and -e $opts{perl};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"perl"} 0 108 108
89 108 ▶ $opts{no_log} = 0 unless $opts{no_log};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"no_log"} 107 1 108
90 108 ▶ $opts{check_warnings} = 1 unless exists $opts{check_warnings};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"check_warnings"} 24 84 108
91  
92 108 ▶ if ( $opts{check_warnings} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"check_warnings"}) 108 0 108
93 108 require String::Perl::Warnings;
94 }
95  
96 108 ▶ if ( $opts{command} eq 'smoke' and !$opts{module} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"command"} eq "smoke" and not $opts{"module"}) 0 108 108
Condition66%2/3
$opts{"command"} eq "smoke" and not $opts{"module"}
!ll&&!rl&&r
71370
MC/DC0%0/2
$opts{"command"} eq "smoke" and not $opts{"module"}
$opts{"command"} eq "smoke" not $opts{"module"}
Truth table66%2/3
A and not(B)
A= $opts{"command"} eq "smoke"B= not $opts{"module"}
ABresult
0X0
100
111
97 0 carp "You must specify a 'module' with 'smoke'\n";
98 0 return;
99 }
100 108 my $self = bless \%opts, $package;
101 108 my @backends = $self->backends();
102 108 my ($type) = grep { /\Q$opts{type}\E$/ } @backends;
103 108 ▶ unless ( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 1 107 108
104 1 carp "No such backend '$opts{type}'\n";
105 1 return;
106 }
107 107 eval "require $type;";
108 107 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 107 107
109 0 carp "Could not load '$type' '$@'\n";
110 0 return;
111 }
112 107 $self->{backend} = $type->new();
113 107 ▶ unless ( $self->{backend} or $self->{backend}->can($self->{command}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"backend"} or $self->{"backend"}->can($self->{"command"})) 0 107 107
Condition33%1/3
$self->{"backend"} or $self->{"backend"}->can($self->{"command"})
l!l&&r!l&&!r
10700
MC/DC0%0/2
$self->{"backend"} or $self->{"backend"}->can($self->{"command"})
$self->{"backend"} $self->{"backend"}->can($self->{"command"})
Truth table33%1/3
A or B
A= $self->{"backend"}B= $self->{"backend"}->can($self->{"command"})
ABresult
1X1
011
000
114 0 croak "Problem loading backend '$type'\n";
115 0 return;
116 }
117 107 ▶ if ( $self->{backend}->can('digest') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"backend"}->can("digest")) 107 0 107
118 107 $self->{_reset_digest} = $self->{backend}->digest();
119 }
120 107 my $cmd = $self->{command};
121 107 $self->{program} = $self->{backend}->$cmd;
122 107 ▶ unless ( $self->{program} or ref $self->{program} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"program"} or ref $self->{"program"} eq "ARRAY") 0 107 107
Condition33%1/3
$self->{"program"} or ref $self->{"program"} eq "ARRAY"
l!l&&r!l&&!r
10700
MC/DC0%0/2
$self->{"program"} or ref $self->{"program"} eq "ARRAY"
$self->{"program"} ref $self->{"program"} eq "ARRAY"
Truth table33%1/3
A or B
A= $self->{"program"}B= ref $self->{"program"} eq "ARRAY"
ABresult
1X1
011
000
123 0 carp "The backend method '$cmd' did not return an arrayref\n";
124 0 return;
125 }
126 107 unshift @{ $self->{program} }, $self->{perl};
127 107 ▶ push @{ $self->{program} }, $self->{module} if $cmd eq 'smoke';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "smoke" 37 70 107
128 107 ▶ $self->{session_id} = POE::Session->create(
Branch: 1 branch
BranchTrueFalseTotal
ref $options eq 'HASH' ? : 7 100 107
129 package_states => [
130 $self => { shutdown => '_shutdown', },
131 $self => [qw(_start _spawn_wheel _wheel_error _wheel_closed _wheel_stdout _wheel_stderr _wheel_idle _wheel_reap _wheel_kill _sig_child)],
132 ],
133 heap => $self,
134 ( ref($options) eq 'HASH' ? ( options => $options ) : () ),
135 )->ID();
136 107 return $self;
137 }
138  
139 sub session_id {
140 0 ▶ return $_[0]->{session_id};
Subroutine session_id: not called CC=1 SCAR=6.9
Pod documented
141 }
142  
143 sub current_log {
144 0 ▶ my $self = shift;
Subroutine current_log: not called CC=2 SCAR=17.9
Pod documented
145 0 ▶ return unless $self->{_wheel_log};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_wheel_log"} 0 0 0
146 0 my $item = Storable::dclone( $self->{_wheel_log} );
147 0 return $item;
148 }
149  
150 sub shutdown {
151 0 ▶ my $self = shift;
Subroutine shutdown: not called CC=1 SCAR=6.9
Pod documented
152 0 $poe_kernel->post( $self->session_id() => 'shutdown' => @_ );
153 }
154  
155 sub _start {
156 107 ▶ my ($kernel,$sender,$self) = @_[KERNEL,SENDER,OBJECT];
Subroutine _start: called CC=7 SCAR=21.6
157 107 $self->{session_id} = $_[SESSION]->ID();
158 107 ▶ if ( $kernel == $sender and !$self->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kernel == $sender and not $self->{"session"}) 0 107 107
Condition33%1/3
$kernel == $sender and not $self->{"session"}
!ll&&!rl&&r
10700
MC/DC0%0/2
$kernel == $sender and not $self->{"session"}
$kernel == $sender not $self->{"session"}
Truth table33%1/3
A and not(B)
A= $kernel == $senderB= not $self->{"session"}
ABresult
0X0
100
111
159 0 croak "Not called from another POE session and 'session' wasn't set\n";
160 }
161 107 my $sender_id;
162 107 ▶ if ( $self->{session} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'session'}) { } 0 107 107
163 0 ▶ if ( my $ref = $kernel->alias_resolve( $self->{session} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $kernel->alias_resolve($self->{'session'})) { } 0 0 0
164 0 $sender_id = $ref->ID();
165 }
166 else {
167 0 croak "Could not resolve 'session' to a valid POE session\n";
168 }
169 }
170 else {
171 107 $sender_id = $sender->ID();
172 }
173 107 $kernel->refcount_increment( $sender_id, __PACKAGE__ );
174 107 $self->{session} = $sender_id;
175 107 ▶ $kernel->detach_myself() if $kernel != $sender;
Branch: 1 branch
BranchTrueFalseTotal
if $kernel != $sender 107 0 107
176  
177 107 $self->{_wheel_log} = [ ];
178  
179 107 ▶ if ( !$self->{_reset_digest} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_reset_digest'}) { } 74 33 107
180 74 $self->_tie_digests();
181 }
182 else {
183 33 $self->{_digests} = { };
184 }
185  
186 107 $self->{_loop_detect} = 0;
187 107 $self->{start_time} = time();
188  
189 107 $kernel->yield( '_spawn_wheel' );
190 107 return;
191 }
192  
193 sub _shutdown {
194 0 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _shutdown: not called CC=2 SCAR=17.9
195 0 ▶ if ( !$self->{_reset_digest} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_reset_digest'}) { } 0 0 0
196 0 $self->_untie_digests();
197 }
198 else {
199 0 delete $self->{_digests};
200 }
201 0 $self->{term_kill} = 1;
202 0 $kernel->yield( '_wheel_kill', 'Killing current due to component shutdown event' );
203 0 return;
204 }
205  
206 # Digests tie and untie
207  
208 sub _tie_digests {
209 74 ▶ my $self = shift;
Subroutine _tie_digests: called CC=2 SCAR=7.0
210 74 $self->{_tempdir} = File::Temp->newdir();
211 74 $self->{_tmpdirname} = $self->{_tempdir}->dirname;
212 74 my $file = File::Spec->catfile( $self->{_tmpdirname}, 'digests.dat' );
213 74 $self->{_digests} = { };
214 74 ▶ tie %{ $self->{_digests} }, 'SDBM_File', $file, O_CREAT|O_RDWR, 0644 or die "Could not tie: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
tie %{$$self{"_digests"};}, "SDBM_File", $file, 66, 420 or die "Could not tie: $!\n" 0 74 74
215 74 return 1;
216 }
217  
218 sub _untie_digests {
219 74 ▶ my $self = shift;
Subroutine _untie_digests: called CC=3 SCAR=11.1
220 74 ▶ if ( $self->{_digests} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_digests"}) 74 0 74
221 74 untie %{ $self->{_digests} };
222 74 delete $self->{_digests};
223 74 delete $self->{_tempdir};
224 74 ▶ rmtree( $self->{_tmpdirname} ) if -d $self->{_tmpdirname};
Branch: 1 branch
BranchTrueFalseTotal
if -d $self->{"_tmpdirname"} 0 74 74
225 }
226 74 return 1;
227 }
228  
229 sub _spawn_wheel {
230 107 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _spawn_wheel: called CC=8 SCAR=21.1
231  
232 # do we need to process callbacks?
233 107 ▶ if ( $self->{do_callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"do_callback"}) 6 101 107
234 # Ask it if we should process this job or not?
235 6 ▶ unless ( $self->{do_callback}->( 'BEFORE', $self ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"do_callback"}->("BEFORE", $self)) 1 5 6
236 1 ▶ warn "Callback denied job, aborting!\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 1 1
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
237 1 my $job = $self->_finalize_job( -1 );
238 1 $job->{cb_kill} = 1;
239 1 $kernel->post( $self->{session}, $self->{event}, $job );
240 1 return;
241 }
242 }
243  
244 # Set appropriate %ENV values before we fork()
245 my $sanctify = Env::Sanctify->sanctify(
246 env => $self->{env},
247 106 sanctify => [
248 '^POE_',
249 '^PERL5_SMOKEBOX',
250 '^HARNESS_',
251 '^(PERL5LIB|TAP_VERSION|TEST_VERBOSE)$',
252 '^AUTHOR_TESTING$',
253 '^PERL_TEST',
254 ] );
255 106 my $type = 'POE::Wheel::Run';
256 106 ▶ $type .= '::Win32' if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 106 106
257 $self->{wheel} = $type->new(
258 Program => $self->{program},
259 106 ▶ StdoutEvent => '_wheel_stdout',
Branch: 1 branch
BranchTrueFalseTotal
$GOT_PTY ? : 106 0 106
260 StderrEvent => '_wheel_stderr',
261 StdoutFilter => POE::Filter::Line->new( InputLiteral => "\n" ),
262 StderrFilter => POE::Filter::Line->new( InputLiteral => "\n" ),
263 ErrorEvent => '_wheel_error',
264 CloseEvent => '_wheel_closed',
265 ( $GOT_PTY ? ( Conduit => 'pty-pipe' ) : () ),
266 );
267 # Restore the %ENV values
268 106 $sanctify->restore();
269 106 $self->{_wheel_time} = time();
270 106 $self->{PID} = $self->{wheel}->PID();
271 106 $kernel->sig_child( $self->{PID}, '_sig_child' );
272 106 ▶ $kernel->delay( '_wheel_idle', $self->{timer} ) unless $self->{command} eq 'index';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"command"} eq "index" 101 5 106
273 106 return;
274 }
275  
276 sub _sig_child {
277 106 ▶ my ($kernel,$self,$thing,$pid,$status) = @_[KERNEL,OBJECT,ARG0..ARG2];
Subroutine _sig_child: called CC=6 SCAR=18.0
278 106 ▶ push @{ $self->{_wheel_log} }, "$thing $pid $status" if ! $self->{no_log};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_log"} 105 1 106
279 106 ▶ warn "$thing $pid $status\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 106 106
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
00106
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
280 106 $kernel->sig_handled();
281 106 $kernel->delay( '_wheel_idle' );
282  
283 106 my $job = $self->_finalize_job( $status );
284  
285 # do we need to process callbacks?
286 106 ▶ if ( $self->{do_callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"do_callback"}) 5 101 106
287 # Inform the callback that the job is done
288 5 $self->{do_callback}->( 'AFTER', $self, $job );
289 }
290  
291 106 $kernel->post( $self->{session}, $self->{event}, $job );
292 106 ▶ $kernel->delay( '_wheel_reap' => $self->{reaper} ) if $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"wheel"} 1 105 106
293 106 return;
294 }
295  
296 sub _finalize_job {
297 107 ▶ my( $self, $status ) = @_;
Subroutine _finalize_job: called CC=7 SCAR=19.6
298  
299 107 $self->{end_time} = time();
300  
301 107 ▶ if ( !$self->{_reset_digest} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_reset_digest'}) { } 74 33 107
302 74 $self->_untie_digests();
303 }
304 else {
305 33 delete $self->{_digests};
306 }
307  
308 107 delete $self->{_loop_detect};
309  
310 107 my $job = { };
311 107 $job->{status} = $status;
312 107 $job->{log} = $self->{_wheel_log};
313 107 $job->{$_} = $self->{extra}->{$_} for keys %{ $self->{extra} };
314 107 $job->{$_} = $self->{$_} for grep { $self->{$_} } qw(command env PID start_time end_time idle_kill excess_kill term_kill perl type);
315 107 ▶ $job->{program} = $self->{program} if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 107 107
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
00107
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
316 107 ▶ $job->{module} = $self->{module} if $self->{command} eq 'smoke';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"command"} eq "smoke" 37 70 107
317 107 $poe_kernel->refcount_decrement( $self->{session}, __PACKAGE__ );
318  
319 107 return $job;
320 }
321  
322 sub _wheel_reap {
323 0 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _wheel_reap: not called CC=3 SCAR=24.8
324 0 ▶ warn "wheel reaped\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 0 0
Condition0%0/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table0%0/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
325 0 delete $self->{wheel};
326 0 return;
327 }
328  
329 sub _wheel_error {
330 212 ▶ my ($self,$operation,$errnum,$errstr,$wheel_id) = @_[OBJECT,ARG0..ARG3];
Subroutine _wheel_error: called CC=5 SCAR=17.2
331 212 ▶ $errstr = "remote end closed" if $operation eq "read" and !$errnum;
Branch: 1 branch
BranchTrueFalseTotal
if $operation eq "read" and not $errnum 106 106 212
Condition66%2/3
$operation eq "read" and not $errnum
!ll&&!rl&&r
0106106
MC/DC50%1/2
$operation eq "read" and not $errnum
$operation eq "read" not $errnum
Truth table66%2/3
A and not(B)
A= $operation eq "read"B= not $errnum
ABresult
0X0
100
111
332 212 ▶ warn "wheel $wheel_id generated $operation error $errnum: $errstr\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 212 212
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
00212
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
333 212 return;
334 }
335  
336 sub _wheel_closed {
337 106 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _wheel_closed: called CC=3 SCAR=11.6
338 106 $kernel->delay( '_wheel_idle' );
339 106 $kernel->delay( '_wheel_reap' );
340 106 ▶ warn "wheel closed\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 106 106
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
00106
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
341 106 delete $self->{wheel};
342 106 return;
343 }
344  
345 sub _wheel_stdout {
346 1124 ▶ my ($self, $input, $wheel_id) = @_[OBJECT, ARG0, ARG1];
Subroutine _wheel_stdout: called CC=6 SCAR=18.1
347 1124 ▶ return if $self->{_killed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_killed"} 688 436 1124
348 436 $self->{_wheel_time} = time();
349 436 ▶ push @{ $self->{_wheel_log} }, $input if ! $self->{no_log};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_log"} 435 1 436
350 436 ▶ warn $input, "\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 436 436
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
00436
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
351 436 ▶ if ( $self->_detect_loop( $input, 'stdout' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_detect_loop($input, "stdout")) 1 435 436
352 1 $self->{excess_kill} = 1;
353 1 $poe_kernel->yield( '_wheel_kill', 'Killing current run due to detection of looping output' );
354 }
355 436 return;
356 }
357  
358 sub _wheel_stderr {
359 42 ▶ my ($self, $input, $wheel_id) = @_[OBJECT, ARG0, ARG1];
Subroutine _wheel_stderr: called CC=7 SCAR=25.7
360 42 ▶ return if $self->{_killed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_killed"} 0 42 42
361 42 $self->{_wheel_time} = time();
362 42 ▶ push @{ $self->{_wheel_log} }, $input if ! $self->{no_log};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_log"} 42 0 42
363 42 ▶ if ( $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}) 0 42 42
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
0042
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
364 0 ▶ if ( length( $input ) > 5000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $input > 5000) { } 0 0 0
365 0 warn "[SUPPRESSED OUTPUT > 5000]\n";
366 }
367 else {
368 0 warn $input, "\n";
369 }
370 }
371 42 ▶ if ( $self->_detect_loop( $input, 'stderr' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_detect_loop($input, "stderr")) 0 42 42
372 0 $self->{excess_kill} = 1;
373 0 $poe_kernel->yield( '_wheel_kill', 'Killing current run due to detection of looping output' );
374 }
375 42 return;
376 }
377  
378 sub _detect_loop {
379 478 ▶ my $self = shift;
Subroutine _detect_loop: called CC=16 SCAR=33.2
380 478 ▶ my $input = shift || return;
Condition50%1/2
shift() || (return)
l!l
4780
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
381 478 ▶ my $handle = shift || 'stdout';
Condition50%1/2
shift() || 'stdout'
l!l
4780
MC/DC0%0/1
shift() || 'stdout'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
382 478 ▶ return if $self->{_loop_detect};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_loop_detect"} 129 349 478
383 349 ▶ if ( my $reset = $self->{_reset_digest} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reset = $self->{"_reset_digest"}) 33 316 349
384 33 ▶ if ( eval { $input =~ $reset } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $input =~ /$reset/ } }) 0 33 33
385 0 ▶ warn "Resetting digests\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 0 0
Condition0%0/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table0%0/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
386 0 $self->{_digests} = { };
387 }
388 }
389 349 ▶ return if $input =~ /^\[(MSG|ERROR)\]/;
Branch: 1 branch
BranchTrueFalseTotal
if $input =~ /^\[(MSG|ERROR)\]/ 0 349 349
390 349 my $digest = sha256_hex( $input );
391  
392 349 my $weighting;
393 349 ▶ if ( $self->{check_warnings} and length( $input ) <= 5000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'check_warnings'} and length $input <= 5000) { } 349 0 349
Condition33%1/3
$self->{"check_warnings"} and length $input <= 5000
!ll&&!rl&&r
00349
MC/DC0%0/2
$self->{"check_warnings"} and length $input <= 5000
$self->{"check_warnings"} length $input <= 5000
Truth table33%1/3
A and B
A= $self->{"check_warnings"}B= length $input <= 5000
ABresult
0X0
100
111
394 349 ▶ $weighting = ( $handle eq 'stderr' and String::Perl::Warnings::is_warning($input) ) ? 1 : 10;
Branch: 1 branch
BranchTrueFalseTotal
$handle eq 'stderr' && String::Perl::Warnings::is_warning($input) ? : 0 349 349
Condition66%2/3
$handle eq "stderr" and String::Perl::Warnings::is_warning($input)
!ll&&!rl&&r
307420
MC/DC0%0/2
$handle eq "stderr" and String::Perl::Warnings::is_warning($input)
$handle eq "stderr" String::Perl::Warnings::is_warning($input)
Truth table66%2/3
A and B
A= $handle eq "stderr"B= String::Perl::Warnings::is_warning($input)
ABresult
0X0
100
111
395 } else {
396 0 ▶ $weighting = $handle eq 'stderr' ? 1 : 10;
Branch: 1 branch
BranchTrueFalseTotal
$handle eq 'stderr' ? : 0 0 0
397 }
398  
399 349 ▶ if ( exists $self->{_digests}->{ $digest } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_digests'}{$digest}) { } 276 73 349
400 276 $self->{_digests}->{ $digest } += $weighting;
401 }
402 else {
403 73 $self->{_digests}->{ $digest } = $weighting;
404 }
405 349 ▶ return unless ++$self->{_digests}->{ $digest } > 3000;
Branch: 1 branch
BranchTrueFalseTotal
unless ++$self->{"_digests"}{$digest} > 3000 348 1 349
406 1 return $self->{_loop_detect} = 1;
407 }
408  
409 sub _wheel_idle {
410 2 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _wheel_idle: called CC=3 SCAR=11.2
411 2 my $now = time();
412 2 ▶ if ( $now - $self->{_wheel_time} >= $self->{idle} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now - $self->{"_wheel_time"} >= $self->{"idle"}) 1 1 2
413 1 $self->{idle_kill} = 1;
414 1 $kernel->yield( '_wheel_kill', 'Killing current run due to excessive idle' );
415 1 return;
416 }
417 1 ▶ if ( $now - $self->{start_time} >= $self->{timeout} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now - $self->{"start_time"} >= $self->{"timeout"}) 1 0 1
418 1 $self->{excess_kill} = 1;
419 1 $kernel->yield( '_wheel_kill', 'Killing current run due to excessive run-time' );
420 1 return;
421 }
422 0 $kernel->delay( '_wheel_idle', 60 );
423 0 return;
424 }
425  
426 sub _wheel_kill {
427 3 ▶ my ($kernel,$self,$reason) = @_[KERNEL,OBJECT,ARG0];
Subroutine _wheel_kill: called CC=12 SCAR=35.0
428 3 ▶ return if $self->{_killed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_killed"} 0 3 3
429 3 $self->{_killed} = 1;
430 3 ▶ push @{ $self->{_wheel_log} }, $reason if ! $self->{no_log};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_log"} 3 0 3
431 3 ▶ warn $reason, "\n" if $self->{debug} or $ENV{PERL5_SMOKEBOX_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"} 0 3 3
Condition33%1/3
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$self->{"debug"} or $ENV{"PERL5_SMOKEBOX_DEBUG"}
$self->{"debug"} $ENV{"PERL5_SMOKEBOX_DEBUG"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $ENV{"PERL5_SMOKEBOX_DEBUG"}
ABresult
1X1
011
000
432 3 ▶ if ( $^O eq 'MSWin32' and $self->{wheel} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32' and $self->{'wheel'}) { } 0 3 3
Condition33%1/3
$^O eq "MSWin32" and $self->{"wheel"}
!ll&&!rl&&r
300
MC/DC0%0/2
$^O eq "MSWin32" and $self->{"wheel"}
$^O eq "MSWin32" $self->{"wheel"}
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= $self->{"wheel"}
ABresult
0X0
100
111
433 0 $self->{wheel}->kill();
434 }
435 else {
436 3 ▶ if ( !$self->{no_grp_kill} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'no_grp_kill'}) { } 0 3 3
437 0 ▶ if ( $^O eq 'solaris' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'solaris') { } 0 0 0
438 0 ▶ kill( 9, '-' . $self->{wheel}->PID() ) if $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"wheel"} 0 0 0
439 }
440 else {
441 0 ▶ $self->{wheel}->kill(-9) if $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"wheel"} 0 0 0
442 }
443 }
444 # elsif ( $GOT_KILLFAM ) {
445 # _kill_family( 9, $self->{wheel}->PID() ) if $self->{wheel};
446 # }
447 else {
448 3 ▶ $self->{wheel}->kill(9) if $self->{wheel};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"wheel"} 3 0 3
449 }
450 }
451 3 return;
452 }
453  
454 47 1;
455  
456 __END__
↑ Summary SmokeBox/JobQueue.pm »