| 1 | package Object::Remote::Role::Connector; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 28 | ▶ | use Module::Runtime qw(use_module); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 28 | ▶ | use Object::Remote::Future; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 14 | ▶ | use Object::Remote::Logging qw(:log :dlog router); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 14 | ▶ | use Moo::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | requires '_open2_for'; | ||||||||||||||
| 9 | |||||||||||||||
| 10 | ▶ | my $timeout_factor = $ENV{PERL_TEST_TIME_OUT_FACTOR} || 1; | |||||||||||||
|
Condition50%1/2
$ENV{'PERL_TEST_TIME_OUT_FACTOR'} || 1
MC/DC0%0/1
$ENV{'PERL_TEST_TIME_OUT_FACTOR'} || 1
$ENV{'PERL_TEST_TIME_OUT_FACTOR'}
Truth table50%1/2
A
A= $ENV{'PERL_TEST_TIME_OUT_FACTOR'}
| |||||||||||||||
| 11 | $timeout_factor = 1 if $timeout_factor < 1; | ||||||||||||||
| 12 | |||||||||||||||
| 13 | 22 | ▶ | has timeout => (is => 'ro', default => sub { 10 * $timeout_factor }); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 14 | ▶ | BEGIN { router()->exclude_forwarding; } | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 20 | ▶ | sub connect { | ||||||||||||
|
Subroutine
connect: called CC=1 SCAR=1.3
Pod
undocumented
| |||||||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
connect: not called CC=1 SCAR=1.3
Pod
undocumented
| |||||||||||||||
| 19 | 0 | ▶ | Dlog_debug { "Preparing to create connection with args of: $_" } @_; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||
| 20 | 0 | my ($send_to_fh, $receive_from_fh, $child_pid) = $self->_open2_for(@_); | |||||||||||||
| 21 | 0 | my $channel = use_module('Object::Remote::ReadChannel')->new( | |||||||||||||
| 22 | fh => $receive_from_fh | ||||||||||||||
| 23 | ); | ||||||||||||||
| 24 | return future { | ||||||||||||||
| 25 | 20 | ▶ | log_trace { "Initializing connection for child pid '$child_pid'" }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 26 | 39 | my $f = shift; | |||||||||||||
| 27 | $channel->on_line_call(sub { | ||||||||||||||
| 28 | 0 | ▶ | if ($_[0] eq "Shere") { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=14.6
Branch: 2 branches
| |||||||||||||||
| 29 | 0 | ▶ | log_trace { "Received 'Shere' from child pid '$child_pid'; setting done handler to create connection" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 30 | 0 | $f->done( | |||||||||||||
| 31 | use_module('Object::Remote::Connection')->new( | ||||||||||||||
| 32 | send_to_fh => $send_to_fh, | ||||||||||||||
| 33 | read_channel => $channel, | ||||||||||||||
| 34 | child_pid => $child_pid, | ||||||||||||||
| 35 | ) | ||||||||||||||
| 36 | ); | ||||||||||||||
| 37 | } else { | ||||||||||||||
| 38 | 0 | ▶ | log_warn { "'Shere' was not found in connection data for child pid '$child_pid'" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 39 | 0 | $f->fail("Expected Shere from remote but received: $_[0]"); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | 0 | undef($channel); | |||||||||||||
| 42 | 39 | }); | |||||||||||||
| 43 | $f->on_fail(sub { | ||||||||||||||
| 44 | # when the future doesn't fail, the connection takes ownership of the child process | ||||||||||||||
| 45 | 1 | ▶ | kill('TERM', $child_pid); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 46 | 1 | waitpid $child_pid, 0; | |||||||||||||
| 47 | 20 | }); | |||||||||||||
| 48 | $channel->on_close_call(sub { | ||||||||||||||
| 49 | 0 | ▶ | log_trace { "Connection has been closed" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 50 | 0 | $f->fail("Channel closed without seeing Shere: $_[0]"); | |||||||||||||
| 51 | 0 | undef($channel); | |||||||||||||
| 52 | 20 | }); | |||||||||||||
| 53 | 39 | ▶ | log_trace { "initialized events on channel for child pid '$child_pid'; creating timeout" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||
| 54 | Object::Remote->current_loop | ||||||||||||||
| 55 | ->watch_time( | ||||||||||||||
| 56 | after => $self->timeout, | ||||||||||||||
| 57 | code => sub { | ||||||||||||||
| 58 | 1 | ▶ | Dlog_trace {"Connection timeout timer has fired for child pid '$child_pid'; is_ready: $_" } $f->is_ready; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 59 | 1 | ▶ | unless($f->is_ready) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 1 | ▶ | log_warn { "Connection with child pid '$child_pid' has timed out" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||
| 61 | 1 | ▶ | $f->fail("Connection timed out") unless $f->is_ready; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | } | ||||||||||||||
| 63 | 0 | undef($channel); | |||||||||||||
| 64 | |||||||||||||||
| 65 | } | ||||||||||||||
| 66 | 20 | ); | |||||||||||||
| 67 | 20 | ▶ | log_trace { "connection for child pid '$child_pid' has been initialized" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||
| 68 | 0 | $f; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | 0 | } | |||||||||||||
| 71 | |||||||||||||||
| 72 | 1; | ||||||||||||||