blib/lib/Paws/API/Retry.pm

filter: Statementstmt 95.2% 60 / 63 Branchbran 91.1% 31 / 34 Conditioncond 100% 21 / 21 MC/DCmcdc 100% 13 / 13 Subroutinesub 96.0% 24 / 25 Podpod 0.0% 0 / 5 totaltotal 92.5% 149 / 161 CC 26 SCAR 9.2
CC
26
Cov
95%
result_is_exception
4.1
should_retry
4.0
__ANON__
3.0
CRAP 2.5
« blib/lib/Paws/S3Control.pm ↑ Summary blib/lib/Paws/Credential/ProviderChain.pm »
1 package Paws::API::Retry;
2 24 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 24 ▶ use MooseX::ClassAttribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶ use Paws::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶ class_has default_rules => (is => 'ro', isa => 'ArrayRef', default => sub { [
Subroutine __ANON__: called CC=1 SCAR=0.0
7 # bad_gateway
8 122 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 502 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 502 68 54 122
9 # gateway_timeout
10 122 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 504 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 504 68 54 122
11 # general_server_error
12 122 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 500 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 500 68 54 122
13 # general_socket_errors
14 122 ▶ sub { $_[0]->code eq 'ConnectionError' },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 # limit_exceeded
16 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 509 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 509 68 6 74
17 # request_throttled_exception
18 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "RequestThrottledException" },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "RequestThrottledException" 32 42 74
Condition100%3/3
defined $_[0]->http_status and $_[0]->http_status == 400
!ll&&!rl&&r
63632
MC/DC100%2/2
defined $_[0]->http_status and $_[0]->http_status == 400
defined $_[0]->http_status $_[0]->http_status == 400
Truth table100%3/3
A and B
A= defined $_[0]->http_statusB= $_[0]->http_status == 400
ABresult
0X0
100
111
19 # service_unavailable
20 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 503 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 503 68 6 74
21 # throttled_exception
22 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "ThrottledException" },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "ThrottledException" 32 42 74
Condition100%3/3
defined $_[0]->http_status and $_[0]->http_status == 400
!ll&&!rl&&r
63632
MC/DC100%2/2
defined $_[0]->http_status and $_[0]->http_status == 400
defined $_[0]->http_status $_[0]->http_status == 400
Truth table100%3/3
A and B
A= defined $_[0]->http_statusB= $_[0]->http_status == 400
ABresult
0X0
100
111
23 # throttling
24 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "Throttling" },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "Throttling" 32 42 74
Condition100%3/3
defined $_[0]->http_status and $_[0]->http_status == 400
!ll&&!rl&&r
63632
MC/DC100%2/2
defined $_[0]->http_status and $_[0]->http_status == 400
defined $_[0]->http_status $_[0]->http_status == 400
Truth table100%3/3
A and B
A= defined $_[0]->http_statusB= $_[0]->http_status == 400
ABresult
0X0
100
111
25 # throttling_exception
26 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "ThrottlingException" },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "ThrottlingException" 32 42 74
Condition100%3/3
defined $_[0]->http_status and $_[0]->http_status == 400
!ll&&!rl&&r
63632
MC/DC100%2/2
defined $_[0]->http_status and $_[0]->http_status == 400
defined $_[0]->http_status $_[0]->http_status == 400
Truth table100%3/3
A and B
A= defined $_[0]->http_statusB= $_[0]->http_status == 400
ABresult
0X0
100
111
27 # throughput_exceeded
28 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "ProvisionedThroughputExceededException" },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 400 and $_[0]->code eq "ProvisionedThroughputExceededException" 32 42 74
Condition100%3/3
defined $_[0]->http_status and $_[0]->http_status == 400
!ll&&!rl&&r
63632
MC/DC100%2/2
defined $_[0]->http_status and $_[0]->http_status == 400
defined $_[0]->http_status $_[0]->http_status == 400
Truth table100%3/3
A and B
A= defined $_[0]->http_statusB= $_[0]->http_status == 400
ABresult
0X0
100
111
29 # too_many_requests
30 74 ▶ sub { defined $_[0]->http_status and $_[0]->http_status == 429 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->http_status and $_[0]->http_status == 429 68 6 74
31 24 ] });
32  
33 24 has max_tries => (is => 'ro', required => 1);
34 24 has type => (is => 'ro', required => 1);
35  
36 24 has tries => (is => 'rw', default => 0);
37  
38 24 has retry_rules => (is => 'ro', required => 1);
39  
40 24 has error_for_die => (is => 'rw');
41 24 has operation_result => (is => 'rw');
42  
43 24 has generator => (is => 'ro');
44  
45 374 ▶ around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
46 374 my ($orig, $class, %args) = @_;
47  
48 374 ▶ if ($args{ type } eq 'exponential') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'type'} eq 'exponential') { } 374 0 374
49 31 ▶ $args{ generator } = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
50 31 my $self = shift;
51 31 (2 ** ($self->tries - 2)) + (rand(1) / 2);
52 374 };
53 } else {
54 0 die "Don't know how to make a retry type of $args{ type }";
55 }
56  
57 374 return $class->$orig(%args);
58 24 };
59  
60 513 ▶ sub should_retry {
Subroutine should_retry: called CC=4 SCAR=13.9
Pod undocumented
61 513 my $self = shift;
62 513 my $res = $self->operation_result;
63  
64 513 ▶ if ($self->result_is_exception and $self->_still_has_retries and $self->exception_is_retriable){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->result_is_exception and $self->_still_has_retries and $self->exception_is_retriable) 53 460 513
Condition100%6/6
$self->result_is_exception and $self->_still_has_retries and $self->exception_is_retriable
!ll&&!rl&&r
3916953
$self->result_is_exception and $self->_still_has_retries
!ll&&!rl&&r
37813122
MC/DC100%3/3
$self->result_is_exception and $self->_still_has_retries and $self->exception_is_retriable
$self->result_is_exception $self->_still_has_retries $self->exception_is_retriable
Truth table100%4/4
A and B and C
A= $self->result_is_exceptionB= $self->_still_has_retriesC= $self->exception_is_retriable
ABCresult
0XX0
10X0
1100
1111
65 53 return 1;
66 }
67 460 return 0; #Anything not exception should not be retried
68 }
69  
70 122 ▶ sub exception_is_retriable {
Subroutine exception_is_retriable: called CC=3 SCAR=11.0
Pod undocumented
71 122 my $self = shift;
72  
73 #Try default_rules, and then the Service's retriables
74 122 foreach my $rule (@{ Paws::API::Retry->default_rules }, @{ $self->retry_rules }){
75 1142 ▶ return 1 if ($rule->($self->operation_result));
Branch: 1 branch
BranchTrueFalseTotal
if &$rule($self->operation_result) 53 1089 1142
76 }
77 }
78  
79 742 ▶ sub result_is_exception {
Subroutine result_is_exception: called CC=4 SCAR=14.1
Pod undocumented
80 742 my $self = shift;
81  
82 742 ▶ die "Don't have an operation_result set yet" if (not defined $self->operation_result);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->operation_result 0 742 742
83  
84 742 ▶ return 0 if (not ref($self->operation_result)); # Scalar results
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->operation_result 0 742 742
85 742 ▶ return 1 if (ref($self->operation_result) eq 'Paws::Exception'); # Exceptions
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->operation_result eq "Paws::Exception" 175 567 742
86 567 return 0; # Rest of objects
87 }
88  
89 402 ▶ sub one_more_try {
Subroutine one_more_try: called CC=1 SCAR=0.0
Pod undocumented
90 402 my $self = shift;
91 402 $self->tries($self->tries + 1);
92 }
93  
94 31 ▶ sub sleep_time {
Subroutine sleep_time: called CC=1 SCAR=0.0
Pod undocumented
95 31 my $self = shift;
96 31 return $self->generator->($self);
97 }
98  
99 135 ▶ sub _still_has_retries {
Subroutine _still_has_retries: called CC=1 SCAR=0.0
100 135 my $self = shift;
101 135 $self->tries < $self->max_tries;
102 }
103  
104 0 ▶ sub _is_retriable {
Subroutine _is_retriable: not called CC=1 SCAR=6.9
105 0 my $self = shift;
106 # TODO: evaluate if the error is retriable depending on class definition
107 0 return 1;
108 }
109  
110 24 __PACKAGE__->meta->make_immutable;
111  
112 24 1;
« blib/lib/Paws/S3Control.pm ↑ Summary blib/lib/Paws/Credential/ProviderChain.pm »