CxnPool/Async/Static.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 86.9% 60 / 69 CC 9 SCAR 18.1
CC
9
Cov
88%
__ANON__
9.9
__ANON__
2.0
next_cxn
1.0
CRAP 6.1
« CxnPool/Async/Sniff.pm ↑ Summary Async/Util.pm »
1 package Search::Elasticsearch::CxnPool::Async::Static;
2 32 $Search::Elasticsearch::CxnPool::Async::Static::VERSION = '6.80';
3 32 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 with 'Search::Elasticsearch::Role::CxnPool::Static',
5 'Search::Elasticsearch::Role::Is_Async';
6  
7 32 ▶use Search::Elasticsearch::Util qw(new_error);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 32 ▶use Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 32 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #===================================
13 sub next_cxn {
14 #===================================
15 11 ▶ my ($self) = @_;
Subroutine next_cxn: called CC=1 SCAR=0.1
Pod documented
16  
17 11 my $cxns = $self->cxns;
18 11 my $now = time();
19 11 my $deferred = deferred;
20  
21 11 my ( %seen, @skipped, $weak_find_cxn );
22  
23 my $find_cxn = sub {
24 31 ▶ my $total = @$cxns;
Subroutine __ANON__: called CC=9 SCAR=23.0
25 31 my $found;
26  
27 31 ▶ if ( $total > keys %seen ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total > keys %seen) 20 11 31
28  
29 # we haven't seen all cxns yet
30 20 ▶ while ( $total-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total--) 20 0 20
31 20 my $cxn = $cxns->[ $self->next_cxn_num ];
32 20 ▶ next if $seen{$cxn}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cxn}++ 0 20 20
33  
34 20 ▶ return $deferred->resolve($cxn)
Branch: 1 branch
BranchTrueFalseTotal
if $cxn->is_live 0 20 20
35 if $cxn->is_live;
36  
37 20 ▶ if ( $cxn->next_ping <= time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cxn->next_ping <= time) 20 0 20
38 20 $found = $cxn;
39 20 last;
40 }
41  
42 0 push @skipped, $cxn;
43 }
44 }
45  
46 31 ▶ if ( $found ||= shift @skipped ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found ||= shift @skipped) 20 11 31
Condition66%2/3
$found ||= shift @skipped
l!l&&r!l&&!r
20011
MC/DC50%1/2
$found ||= shift @skipped
$found shift @skipped
Truth table66%2/3
A ||= B
A= $foundB= shift @skipped
ABresult
1X1
011
000
47 return $found->pings_ok->then(
48 0 ▶ sub { $deferred->resolve($found) }, # success
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 20 $weak_find_cxn # resolve
50 );
51 }
52  
53 11 $_->force_ping for @$cxns;
54  
55 11 return $deferred->reject(
56 new_error(
57 "NoNodes", "No nodes are available: [" . $self->cxns_str . ']'
58 )
59 );
60  
61 11 };
62 11 weaken( $weak_find_cxn = $find_cxn );
63  
64 11 $find_cxn->();
65 11 $deferred->promise;
66 }
67  
68 32 1;
69  
70 # ABSTRACT: An async CxnPool for connecting to a remote cluster with a static list of nodes.
71  
72 __END__
« CxnPool/Async/Sniff.pm ↑ Summary Async/Util.pm »