blib/lib/Google/Auth/RetryHelper.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 83.3% 5 / 6 Conditioncond 60.0% 9 / 15 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 80.8% 59 / 73 CC 10 SCAR 20.3
CC
10
Cov
85%
execute_with_retry
10.9
BEGIN
1.0
BEGIN
1.0
CRAP 7.6
« blib/lib/Google/Auth/Stores/FileTokenStore.pm ↑ Summary blib/lib/Google/Auth/ServiceAccountCredentials.pm »
1 # Copyright 2026 Google LLC and contributors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14  
15 package Google::Auth::RetryHelper;
16  
17 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 15 ▶use Google::Auth::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 15 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 15 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 9 ▶sub execute_with_retry {
Subroutine execute_with_retry: called CC=10 SCAR=23.9
Pod undocumented
25 9 my ($class, $code, %options) = @_;
26  
27 9 ▶ my $max_retries = $options{max_retries} // 3;
Condition100%2/2
$options{"max_retries"} // 3
l!l
18
MC/DC100%1/1
$options{"max_retries"} // 3
$options{"max_retries"}
Truth table100%2/2
A
A= $options{"max_retries"}
Aresult
11
00
28 9 ▶ my $initial_delay = $options{initial_delay} // 1.0;
Condition100%2/2
$options{"initial_delay"} // 1
l!l
18
MC/DC100%1/1
$options{"initial_delay"} // 1
$options{"initial_delay"}
Truth table100%2/2
A
A= $options{"initial_delay"}
Aresult
11
00
29 9 ▶ my $backoff_factor = $options{backoff_factor} // 2.0;
Condition100%2/2
$options{"backoff_factor"} // 2
l!l
18
MC/DC100%1/1
$options{"backoff_factor"} // 2
$options{"backoff_factor"}
Truth table100%2/2
A
A= $options{"backoff_factor"}
Aresult
11
00
30  
31 9 my $attempt = 0;
32 9 my $delay = $initial_delay;
33  
34 9 while (1) {
35 14 $attempt++;
36 14 my $res = eval { $code->() };
37 14 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 6 8 14
38 6 return $res;
39 }
40  
41 8 my $err = $@;
42 8 ▶ if ($attempt >= $max_retries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attempt >= $max_retries) 3 5 8
43 3 $log->errorf('Max retry attempts (%d/%d) reached. Throwing error: %s',
44 $attempt, $max_retries, $err);
45 3 die $err;
46 }
47  
48 5 ▶ if ( $err =~ /Credential file.*does not exist/i
Branch: 1 branch
BranchTrueFalseTotal
if ($err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i or $err =~ /Invalid credential_source/i) 0 5 5
Condition33%3/9
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i or $err =~ /Invalid credential_source/i
l!l&&r!l&&!r
005
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i
l!l&&r!l&&!r
005
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i
l!l&&r!l&&!r
005
MC/DC0%0/4
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i or $err =~ /Invalid credential_source/i
$err =~ /Credential file.*does not exist/i $err =~ /Missing required/i $err =~ /Ambiguous/i $err =~ /Invalid credential_source/i
Truth table20%1/5
A or B or C or D
A= $err =~ /Credential file.*does not exist/iB= $err =~ /Missing required/iC= $err =~ /Ambiguous/iD= $err =~ /Invalid credential_source/i
ABCDresult
1XXX1
01XX1
001X1
00011
00000
49 || $err =~ /Missing required/i
50 || $err =~ /Ambiguous/i
51 || $err =~ /Invalid credential_source/i)
52 {
53 0 $log->errorf('Fatal un-retryable error encountered: %s. Propagating...',
54 $err);
55 0 die $err;
56 }
57  
58 $log->warnf(
59 5 'Transient error on attempt %d/%d: %s. Retrying in %s seconds...',
60 $attempt, $max_retries, $err, $delay);
61 5 Time::HiRes::sleep($delay);
62 5 $delay *= $backoff_factor;
63 }
64 }
65  
66 15 1;
« blib/lib/Google/Auth/Stores/FileTokenStore.pm ↑ Summary blib/lib/Google/Auth/ServiceAccountCredentials.pm »