blib/lib/App/Prove/Plugin/Distributed.pm

filter: Statementstmt 64.2% 167 / 260 Branchbran 30.5% 33 / 108 Conditioncond 45.4% 10 / 22 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 88.0% 22 / 25 Podpod 100% 5 / 5 totaltotal 55.0% 239 / 434 CC 69 SCAR 44.2
CC
69
Cov
54%
load
213.1
start_server
56.6
__ANON__
30.0
CRAP 83.1
↑ Summary blib/lib/TAP/Parser/SourceHandler/Worker.pm »
1 package App::Prove::Plugin::Distributed;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use constant LOCK_EX => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use constant LOCK_NB => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use vars (qw($VERSION @ISA));
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 my $error = '';
18  
19 =head1 NAME
20  
21 App::Prove::Plugin::Distributed - an L<App::Prove> plugin to distribute test jobs using client and server model.
22  
23 =head1 VERSION
24  
25 Version 0.08
26  
27 =cut
28  
29 3 $VERSION = '0.08';
30  
31 =head1 SYNOPSIS
32  
33 # All of the examples below is loading tests into the worker perl processes
34 # If you want to run the tests in a separate perl process, you can specify
35 # the '--detach' option to accomplish that.
36
37 # Default workers with L<IPC::Open3> as worker processes.
38 prove -PDistributed -j2 t/
39  
40 # Distributed jobs with LSF workers.
41 prove -PDistributed --distributed-type=LSF -j2 t/
42  
43 # Distributed jobs with SSH workers.
44 prove -PDistributed --distributed-type=SSH -j2 --hosts=host1,host2 t/
45  
46 # If you are using home network that does not have name server setup,
47 # you can specify the option --use-local-public-ip
48 prove -PDistributed --distributed-type=SSH --use-local-public-ip -j2 --hosts=host1,host2 t/
49
50 # Distributed jobs with PBS workers using L<PBS::Client>. Note: This is not tested yet.
51 prove -PDistributed --distributed-type=PBS -j2 t/
52  
53 # Distributed jobs with PBS workers using L<PBS::Client>. Note: This is not tested yet.
54 # With PBS option
55 prove -PDistributed --distributed-type=PBS --mem=200 -j2 t/
56  
57 =head1 DESCRIPTION
58  
59 A plugin for App::Prove to distribute job. The core implementation of the plugin is to
60 provide a easy interface and functionality to extend the use of any distribution method.
61  
62 The initiate release of this module was using the idea from L<FCGI::Daemon> that load perl
63 code file using "do" perl function to the worker perl process to execute tests.
64  
65 Currently, the distribution comes with a few implementation of distribution methods to
66 initiate external "worker" processes.
67 Shown below is the list.
68
69 L<IPC::Open3>
70 LSF
71 SSH
72 L<PBS::Client> * Note: PBS implemetation is not tested yet.
73  
74 =head1 FUNCTIONS
75  
76 Basic functions.
77  
78 =head3 C<load>
79  
80 Load the plugin configuration.
81 It will setup all of the tests to be distributed through the
82 L<TAP::Parser::SourceHandler::Worker> source handler class.
83  
84 =cut
85  
86 2 ▶sub load {
Subroutine load: called CC=31 SCAR=53.6
Pod documented
87 2 my ( $class, $p ) = @_;
88 2 my @args = @{ $p->{args} };
89 2 my $app = $p->{app_prove};
90 {
91 2 local @ARGV = @args;
92  
93 0 push @ARGV, grep { /^--/ } @{ $app->{argv} };
94 0 $app->{argv} = [ grep { !/^--/ } @{ $app->{argv} } ];
95 2 Getopt::Long::Configure(qw(no_ignore_case bundling pass_through));
96  
97 # Don't add coderefs to GetOptions
98 GetOptions(
99 'manager=s' => \$app->{manager},
100 'distributed-type=s' => \$app->{distributed_type},
101 'start-up=s' => \$app->{start_up},
102 'tear-down=s' => \$app->{tear_down},
103 'error-log=s' => \$app->{error_log},
104 'detach' => \$app->{detach},
105 'sync-type=s' => \$app->{sync_type},
106 'source-dir=s' => \$app->{source_dir},
107 'destination-dir=s' => \$app->{destination_dir},
108 2 ▶ ) or croak('Unable to continue');
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("manager=s", \$app->{"manager"}, "distributed-type=s", \$app->{"distributed_type"}, "start-up=s", \$app->{"start_up"}, "tear-down=s", \$app->{"tear_down"}, "error-log=s", \$app->{"error_log"}, "detach", \$app->{"detach"}, "sync-type=s", \$app->{"sync_type"}, "source-dir=s", \$app->{"source_dir"}, "destination-dir=s", \$app->{"destination_dir"}) or croak("Unable to continue") 2 0 2
109  
110 #LSF: We pass the option to the source handler if the source handler want the options.
111 2 ▶ unless ( $app->{manager} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($app->{"manager"}) 0 2 2
112 my $source_handler_class =
113 'TAP::Parser::SourceHandler::'
114 . 'Worker'
115 . (
116 $app->{distributed_type}
117 ? '::' . $app->{distributed_type}
118 0 ▶ : ''
Branch: 1 branch
BranchTrueFalseTotal
$app->{'distributed_type'} ? : 0 0 0
119 );
120 0 eval "use $source_handler_class";
121 0 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
122 0 ▶ unless ( $source_handler_class->load_options( $app, \@ARGV ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($source_handler_class->load_options($app, \@ARGV)) 0 0 0
123 0 croak('Unable to continue without needed worker options.');
124 }
125 }
126 }
127  
128 }
129 2 my $type = $app->{distributed_type};
130 2 ▶ my $option_name = '--worker' . ( $type ? '-' . lc($type) : '' ) . '-option';
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 0 2 2
131 2 ▶ if ( $app->{argv}->[0]
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{'argv'}[0] and $app->{'argv'}[0] =~ /$option_name=number_of_workers=(\d+)/) { } 0 2 2
Condition33%1/3
$app->{"argv"}[0] and $app->{"argv"}[0] =~ /$option_name=number_of_workers=(\d+)/
!ll&&!rl&&r
200
MC/DC0%0/2
$app->{"argv"}[0] and $app->{"argv"}[0] =~ /$option_name=number_of_workers=(\d+)/
$app->{"argv"}[0] $app->{"argv"}[0] =~ /$option_name=number_of_workers=(\d+)/
Truth table33%1/3
A and B
A= $app->{"argv"}[0]B= $app->{"argv"}[0] =~ /$option_name=number_of_workers=(\d+)/
ABresult
0X0
100
111
132 && $app->{argv}->[0] =~ /$option_name=number_of_workers=(\d+)/ )
133 {
134 0 ▶ if ( $app->{jobs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{'jobs'}) { } 0 0 0
135 0 die
136 "-j and $option_name=number_of_workers are mutually exclusive.\n";
137 }
138 else {
139 0 $app->{jobs} = $1;
140 }
141 }
142 else {
143 2 ▶ $app->{jobs} ||= 1;
Condition50%1/2
$app->{"jobs"} ||= 1
l!l
02
MC/DC0%0/1
$app->{"jobs"} ||= 1
$app->{"jobs"}
Truth table50%1/2
A
A= $app->{"jobs"}
Aresult
11
00
144 2 unshift @{ $app->{argv} },
145 2 "$option_name=number_of_workers=" . $app->{jobs};
146 }
147  
148 2 for (
149 qw(start_up tear_down error_log detach sync_type source_dir destination_dir)
150 )
151 {
152 14 ▶ if ( $app->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{$_}) 0 14 14
153 0 unshift @{ $app->{argv} }, "$option_name=$_=" . $app->{$_};
154 }
155 }
156  
157 2 ▶ if ( $app->{sync_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{"sync_type"}) 0 2 2
158  
159 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
160 #LSF: If we do rsync, that means we want to keep the switches unmodified.
161 0 ▶ *App::Prove::_get_lib = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
162 0 my $self = shift;
163 0 my @libs;
164 0 ▶ if ( $self->lib ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lib) 0 0 0
165 0 push @libs, 'lib';
166 }
167 0 ▶ if ( $self->blib ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->blib) 0 0 0
168 0 push @libs, 'blib/lib', 'blib/arch';
169 }
170 0 ▶ if ( @{ $self->includes } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->includes;}) 0 0 0
171 0 push @libs, @{ $self->includes };
172 }
173  
174 #LSF: Override the original not to do the abs path.
175 #@libs = map { File::Spec->rel2abs($_) } @libs;
176  
177 # Huh?
178 0 ▶ return @libs ? \@libs : ();
Branch: 1 branch
BranchTrueFalseTotal
@libs ? : 0 0 0
179  
180 0 };
181 }
182  
183 2 ▶ unless ( $app->{manager} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($app->{"manager"}) 0 2 2
184  
185 #LSF: Set the iterator.
186 $app->sources(
187 [
188 'Worker'
189 . (
190 $app->{distributed_type}
191 ? '::' . $app->{distributed_type}
192 0 ▶ : ''
Branch: 1 branch
BranchTrueFalseTotal
$app->{'distributed_type'} ? : 0 0 0
193 )
194 ]
195 );
196 0 return 1;
197 }
198  
199 2 ▶ my $original_perl_5_lib = $ENV{PERL5LIB} || '';
Condition50%1/2
$ENV{'PERL5LIB'} || ''
l!l
20
MC/DC0%0/1
$ENV{'PERL5LIB'} || ''
$ENV{'PERL5LIB'}
Truth table50%1/2
A
A= $ENV{'PERL5LIB'}
Aresult
11
00
200 2 my @original_include = $class->extra_used_libs();
201 2 ▶ if ( $app->{includes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{"includes"}) 2 0 2
202 2 my @includes = split /:/, $original_perl_5_lib;
203 2 unshift @includes, @original_include;
204 2 unshift @includes, @{ $app->{includes} };
205 2 my %found;
206 my @wanted;
207 2 for my $include (@includes) {
208 4 ▶ unless ( $found{$include}++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found{$include}++) 4 0 4
209 4 push @wanted, $include;
210 }
211 }
212 2 $ENV{PERL5LIB} = join ':', @wanted;
213  
214 #LSF: Put the extra libraries to @INC.
215 2 %found = map { $_ => 1 } @INC;
216 2 for (@wanted) {
217 4 ▶ unshift @INC, $_ unless ( $found{$_} );
Branch: 1 branch
BranchTrueFalseTotal
unless $found{$_} 0 4 4
218 }
219 }
220  
221 #LSF: Sync test environment here.
222 2 ▶ if ( $app->{sync_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{"sync_type"}) 0 2 2
223 0 my $method = $app->{sync_type} . '_test_env';
224 0 ▶ unless ( $class->can($method) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can($method)) 0 0 0
225 die "not able to sync on the remote with type "
226 . $app->{sync_type}
227 0 . ".\nCurrently, only the rsync type is supported.\n";
228 }
229  
230 0 ▶ unless ( $class->$method($app) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->$method($app)) 0 0 0
231 0 die $error;
232 }
233 }
234  
235 #LSF: Start up.
236 2 ▶ if ( $app->{start_up} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{"start_up"}) 0 2 2
237 0 ▶ unless ( $class->_do( $app->{start_up} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->_do($app->{"start_up"})) 0 0 0
238 0 die "start server error with error [$error].\n";
239 }
240 }
241  
242 2 while (1) {
243  
244 #LSF: The is the server to serve the test.
245 $class->start_server(
246 app => $app,
247 spec => $app->{manager},
248 ( $app->{error_log} ? ( error_log => $app->{error_log} ) : () ),
249 2 ▶ ( $app->{detach} ? ( detach => $app->{detach} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
$app->{'error_log'} ? : 0 2 2
$app->{'detach'} ? : 0 2 2
250  
251 );
252 }
253  
254 #LSF: Anything below here might not be called.
255 #LSF: Tear down
256 0 ▶ if ( $app->{tear_down} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->{"tear_down"}) 0 0 0
257 0 ▶ unless ( $class->_do( $app->{tear_down} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->_do($app->{"tear_down"})) 0 0 0
258 0 die "tear down error with error [$error].\n";
259 }
260 }
261 0 $ENV{PER5LIB} = $original_perl_5_lib;
262 0 @INC = @original_include;
263 0 return 1;
264 }
265  
266 =head3 C<extra_used_libs>
267  
268 Return a list of paths in @INC that are not part of the compiled-in lsit of paths
269  
270 =cut
271  
272 3 my @initial_compiled_inc;
273  
274 3 ▶BEGIN {
Subroutine BEGIN: called CC=6 SCAR=17.9
275 3 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
276  
277 3 my @var_list = (
278 'updatesarch', 'updateslib', 'archlib', 'privlib',
279 'sitearch', 'sitelib', 'sitelib_stem', 'vendorarch',
280 'vendorlib', 'vendorlib_stem', 'extrasarch', 'extraslib',
281 );
282  
283 3 for my $var_name (@var_list) {
284 36 ▶ if ( $var_name =~ /_stem$/ && $Config{$var_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_name =~ /_stem$/ and $App::Prove::Plugin::Distributed::Config{$var_name}) { } 3 33 36
Condition100%3/3
$var_name =~ /_stem$/ and $App::Prove::Plugin::Distributed::Config{$var_name}
!ll&&!rl&&r
3033
MC/DC100%2/2
$var_name =~ /_stem$/ and $App::Prove::Plugin::Distributed::Config{$var_name}
$var_name =~ /_stem$/ $App::Prove::Plugin::Distributed::Config{$var_name}
Truth table100%3/3
A and B
A= $var_name =~ /_stem$/B= $App::Prove::Plugin::Distributed::Config{$var_name}
ABresult
0X0
100
111
285 3 my @stem_list = ( split( ' ', $Config{'inc_version_list'} ), '' );
286 push @initial_compiled_inc,
287 3 map { $Config{$var_name} . "/$_" } @stem_list;
288 }
289 else {
290 push @initial_compiled_inc, $Config{$var_name}
291 33 ▶ if $Config{$var_name};
Branch: 1 branch
BranchTrueFalseTotal
if $App::Prove::Plugin::Distributed::Config{$var_name} 12 21 33
292 }
293 }
294  
295 # . is part of the initial @INC unless in taint mode
296 3 ▶ push @initial_compiled_inc, '.' if ( ${^TAINT} == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if ${^TAINT} == 0 3 0 3
297  
298 3 map { s/\/+/\//g } @initial_compiled_inc;
299 3 map { s/\/+$// } @initial_compiled_inc;
300 }
301  
302 2 ▶sub extra_used_libs {
Subroutine extra_used_libs: called CC=6 SCAR=18.1
Pod documented
303 2 my $class = shift;
304  
305 2 my @extra;
306 2 my @compiled_inc = @initial_compiled_inc;
307 2 my @perl5lib = split( ':', $ENV{PERL5LIB} );
308 2 map { $_ =~ s/\/+$// }
309 ( @compiled_inc, @perl5lib ); # remove trailing slashes
310 2 ▶ map { $_ = Cwd::abs_path($_) || $_ } ( @compiled_inc, @perl5lib );
Condition33%1/3
Cwd::abs_path($_) || $_
l!l&&r!l&&!r
1400
MC/DC0%0/2
Cwd::abs_path($_) || $_
Cwd::abs_path($_) $_
Truth table33%1/3
A || B
A= Cwd::abs_path($_)B= $_
ABresult
1X1
011
000
311 2 for my $inc (@INC) {
312 16 $inc =~ s/\/+$//;
313 16 ▶ my $abs_inc = Cwd::abs_path($inc)
Condition33%1/3
Cwd::abs_path($inc) || $inc
l!l&&r!l&&!r
1600
MC/DC0%0/2
Cwd::abs_path($inc) || $inc
Cwd::abs_path($inc) $inc
Truth table33%1/3
A || B
A= Cwd::abs_path($inc)B= $inc
ABresult
1X1
011
000
314 || $inc; # should already be expanded by UR.pm
315 16 ▶ next if ( grep { $_ =~ /^$abs_inc$/ } @compiled_inc );
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /^$abs_inc$/;} @compiled_inc 8 8 16
316 8 ▶ next if ( grep { $_ =~ /^$abs_inc$/ } @perl5lib );
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /^$abs_inc$/;} @perl5lib 6 2 8
317 2 push @extra, $inc;
318 }
319  
320 #unshift @extra, ($ENV{PERL_USED_ABOVE} ? split(":", $ENV{PERL_USED_ABOVE}) : ());
321  
322 2 map { $_ =~ s/\/+$// } @extra; # remove trailing slashes again
323 #@extra = _unique_elements(@extra);
324  
325 2 return @extra;
326 }
327  
328 =head3 C<start_server>
329  
330 Start a server to serve the test.
331  
332 Parameter is the contoller peer address.
333  
334 =cut
335  
336 2 ▶sub start_server {
Subroutine start_server: called CC=13 SCAR=40.4
Pod documented
337 2 my $class = shift;
338 2 my %args = @_;
339 my ( $app, $spec, $error_log, $detach ) =
340 2 @args{ 'app', 'spec', 'error_log', 'detach' };
341  
342 2 my $socket = IO::Socket::INET->new(
343 PeerAddr => $spec,
344 Proto => 'tcp'
345 );
346 2 ▶ unless ($socket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($socket) 0 2 2
347 0 die "failed to connect to controller with address : $spec.\n";
348 }
349  
350 #LSF: Waiting for job from controller.
351 2 my $job_info = <$socket>;
352 2 chomp($job_info);
353  
354 #LSF: Run job.
355 2 my $pid = fork();
356 2 ▶ if ($pid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pid) { } 0 2 2
elsif ($pid == 0) { } 2 0 2
357 0 waitpid( $pid, 0 );
358 }
359 elsif ( $pid == 0 ) {
360  
361 #LSF: Intercept all output from Test::More. Output all of them at one.
362 2 my $builder = Test::More->builder;
363 2 $builder->output($socket);
364 2 $builder->failure_output($socket);
365 2 $builder->todo_output($socket);
366 2 ▶ if ($detach) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detach) 0 2 2
367 my @command =
368 ( $job_info,
369 0 ▶ ( $app->{test_args} ? @{ $app->{test_args} } : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$app->{'test_args'} ? : 0 0 0
370 {
371 0 require TAP::Parser::Source;
372 0 require TAP::Parser::SourceHandler::Worker;
373 0 require TAP::Parser::SourceHandler::Perl;
374 0 my $source = TAP::Parser::Source->new();
375 0 $source->raw( \$job_info )->assemble_meta;
376 0 my $vote =
377 TAP::Parser::SourceHandler::Worker->can_handle($source);
378 0 ▶ if ( $vote > 0.25 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vote > "0.25") 0 0 0
379 0 unshift @command,
380 TAP::Parser::SourceHandler::Perl->get_perl();
381 }
382 0 open STDOUT, ">&", $socket;
383 0 open STDERR, ">&", $socket;
384 0 ▶ exec(@command)
Branch: 1 branch
BranchTrueFalseTotal
exec @command or print $socket "Error running command: $!\nCommand was: ", join(" ", @command), "\n" 0 0 0
385 or print $socket "Error running command: $!\nCommand was: ",
386 join( ' ', @command ), "\n";
387 }
388 0 exit;
389 }
390 2 *STDERR = $socket;
391 2 *STDOUT = $socket;
392 2 ▶ unless ( $class->_do( $job_info, $app->{test_args} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->_do($job_info, $app->{"test_args"})) 0 2 2
393 0 ▶ my $server_spec = (
Branch: 1 branch
BranchTrueFalseTotal
$socket->sockhost eq '0.0.0.0' ? : 0 0 0
394 $socket->sockhost eq '0.0.0.0'
395 ? hostname
396 : $socket->sockhost
397 )
398 . ':'
399 . $socket->sockport;
400 0 print $socket (
401 '# ',
402 ( join "\n# ", ( "Worker: <$spec>", ( split /\n/, $error ) ) ),
403 "\n"
404 );
405 0 ▶ if ($error_log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error_log) 0 0 0
406 3 ▶ use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
407 0 my $fh = IO::File->new( "$error_log", 'a+' );
408 0 ▶ unless ( flock( $fh, LOCK_EX | LOCK_NB ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 6) 0 0 0
409 0 warn "can't immediately write-lock ",
410 "the file ($!), blocking ...";
411 0 ▶ unless ( flock( $fh, LOCK_EX ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 2) 0 0 0
412 0 die "can't get write-lock on numfile: $!";
413 }
414 }
415 0 print $fh (
416 join "\n",
417 (
418 "<< START $job_info >>",
419 "SERVER: $server_spec",
420 "PID: $$",
421 "ERROR: $error",
422 "<< END $job_info >>"
423 )
424 );
425 0 close $fh;
426 }
427 }
428  
429 #LSF: How to exit with END block trigger.
430 2 &trigger_end_blocks_before_child_process_exit();
431  
432 #LSF: Might not need this.
433 2 $socket->flush;
434 2 exit(0);
435 }
436 else {
437 0 die "should not get here.\n";
438 }
439 0 $socket->close();
440 0 return 1;
441 }
442  
443 2 ▶sub _do {
Subroutine _do: called CC=5 SCAR=18.9
444 2 my $proto = shift;
445 2 my $job_info = shift;
446 2 my $args = shift;
447 2 my $cwd = File::Spec->rel2abs('.');
448  
449 #LSF: The code from here to exit is from L<FCGI::Daemon> module.
450 0 ▶ local *CORE::GLOBAL::exit = sub { die 'notr3a11yeXit' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
451 2 local $0 = $job_info; #fixes FindBin (in English $0 means $PROGRAM_NAME)
452 3 ▶ no strict; # default for Perl5
Subroutine BEGIN: called CC=1 SCAR=0.0
453 {
454  
455 2 package main;
456 2 ▶ local @ARGV = $args ? @$args : ();
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 2 2
457 2 do $0; # do $0; could be enough for strict scripts
458 2 chdir($cwd);
459  
460 2 ▶ if ($EVAL_ERROR) {
Branch: 2 branches
BranchTrueFalseTotal
if ($EVAL_ERROR) { } 0 2 2
elsif ($@) { } 0 2 2
461 0 $EVAL_ERROR =~ s{\n+\z}{};
462 0 ▶ unless ( $EVAL_ERROR =~ m{^notr3a11yeXit} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($EVAL_ERROR =~ /^notr3a11yeXit/) 0 0 0
463 0 $error = $EVAL_ERROR;
464 0 return;
465 }
466 }
467 elsif ($@) {
468 0 $error = $@;
469 0 return;
470 }
471 }
472 2 return 1;
473 }
474  
475 =head3 C<trigger_end_blocks_before_child_process_exit>
476  
477 Trigger END blocks before the child process exit.
478 The main reason is to have the Test::Builder to have
479 change to finish up.
480  
481 =cut
482  
483 2 ▶sub trigger_end_blocks_before_child_process_exit {
Subroutine trigger_end_blocks_before_child_process_exit: called CC=6 SCAR=19.1
Pod documented
484 2 my $original_pid;
485 2 ▶ if ( $Test::Builder::Test && $Test::Builder::Test->{Original_Pid} != $$ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Test::Builder::Test and $Test::Builder::Test->{"Original_Pid"} != $$) 2 0 2
Condition33%1/3
$Test::Builder::Test and $Test::Builder::Test->{"Original_Pid"} != $$
!ll&&!rl&&r
002
MC/DC0%0/2
$Test::Builder::Test and $Test::Builder::Test->{"Original_Pid"} != $$
$Test::Builder::Test $Test::Builder::Test->{"Original_Pid"} != $$
Truth table33%1/3
A and B
A= $Test::Builder::TestB= $Test::Builder::Test->{"Original_Pid"} != $$
ABresult
0X0
100
111
486 2 $original_pid = $Test::Builder::Test->{Original_Pid};
487 2 $Test::Builder::Test->{Original_Pid} = $$;
488 }
489 3 ▶ use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
490 2 my @ENDS = B::end_av->ARRAY;
491 2 for my $END (@ENDS) {
492 14 $END->object_2svref->();
493 }
494 2 ▶ if ( $Test::Builder::Test && $original_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Test::Builder::Test and $original_pid) 2 0 2
Condition33%1/3
$Test::Builder::Test and $original_pid
!ll&&!rl&&r
002
MC/DC0%0/2
$Test::Builder::Test and $original_pid
$Test::Builder::Test $original_pid
Truth table33%1/3
A and B
A= $Test::Builder::TestB= $original_pid
ABresult
0X0
100
111
495 2 $Test::Builder::Test->{Original_Pid} = $original_pid;
496 }
497 }
498  
499 =head3 C<rsync_test_env>
500  
501 Rsync test enviroment to the worker host.
502  
503 Parameters $app object
504 Returns boolean
505  
506 =cut
507  
508 0 ▶sub rsync_test_env {
Subroutine rsync_test_env: not called CC=4 SCAR=30.0
Pod documented
509 0 my $proto = shift;
510 0 my $app = shift;
511 0 my $manager = $app->{manager};
512  
513 0 my ( $host, $port ) = split /:/, $manager, 2;
514 0 my $dest = $app->{destination_dir};
515 0 ▶ unless ($dest) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dest) 0 0 0
516 0 require File::Temp;
517 0 $dest = File::Temp::tempdir();
518 }
519  
520 #LSF: Some system the rsync will not automatically using the current user.
521 # Let get the user for rsync.
522 0 my $user = $ENV{USER};
523  
524 0 my $source = $app->{source_dir};
525 0 require File::Rsync;
526 0 my $rsync = File::Rsync->new( { archive => 1, compress => 1 } );
527 $rsync->exec(
528 {
529 src => ( $user ? "$user\@" : '' ) . "$host:$source",
530 dest => "$dest",
531 }
532 0 ▶ ) or do { $error = "rsync failed\n$!"; return; };
Branch: 2 branches
BranchTrueFalseTotal
$rsync->exec({"src", ($user ? "$user\@" : "") . "${host}:$source", "dest", "$dest"}) or do { $error = "rsync failed\n$!"; return } 0 0 0
$user ? : 0 0 0
533  
534 #LSF: Let change directory to destination.
535 0 chdir "$dest";
536  
537 0 return 1;
538 }
539  
540 3 1;
541  
542 __END__
↑ Summary blib/lib/TAP/Parser/SourceHandler/Worker.pm »