blib/lib/Google/Auth/RetryHelper.pm

filter: Statementstmt 92.1% 35 / 38 Branchbran 66.6% 4 / 6 Conditioncond 40.0% 6 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 69.8% 51 / 73 CC 10 SCAR 22.3
CC
10
Cov
76%
execute_with_retry
13.5
BEGIN
1.0
BEGIN
1.0
CRAP 9.3
« blib/lib/Google/Auth/UserAuthorizer.pm ↑ Summary blib/lib/Google/Auth/WebUserAuthorizer.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 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 17 ▶use Google::Auth::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 17 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 17 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶sub execute_with_retry {
Subroutine execute_with_retry: called CC=10 SCAR=26.0
Pod undocumented
25 4 my ($class, $code, %options) = @_;
26  
27 4 ▶ my $max_retries = $options{max_retries} // 3;
Condition50%1/2
$options{"max_retries"} // 3
l!l
04
MC/DC0%0/1
$options{"max_retries"} // 3
$options{"max_retries"}
Truth table50%1/2
A
A= $options{"max_retries"}
Aresult
11
00
28 4 ▶ my $initial_delay = $options{initial_delay} // 1.0;
Condition50%1/2
$options{"initial_delay"} // 1
l!l
04
MC/DC0%0/1
$options{"initial_delay"} // 1
$options{"initial_delay"}
Truth table50%1/2
A
A= $options{"initial_delay"}
Aresult
11
00
29 4 ▶ my $backoff_factor = $options{backoff_factor} // 2.0;
Condition50%1/2
$options{"backoff_factor"} // 2
l!l
04
MC/DC0%0/1
$options{"backoff_factor"} // 2
$options{"backoff_factor"}
Truth table50%1/2
A
A= $options{"backoff_factor"}
Aresult
11
00
30  
31 4 my $attempt = 0;
32 4 my $delay = $initial_delay;
33  
34 4 while (1) {
35 12 $attempt++;
36 12 my $res = eval { $code->() };
37 12 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 12 12
38 0 return $res;
39 }
40  
41 12 my $err = $@;
42 12 ▶ if ($attempt >= $max_retries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attempt >= $max_retries) 4 8 12
43 4 $log->errorf('Max retry attempts (%d/%d) reached. Throwing error: %s',
44 $attempt, $max_retries, $err);
45 4 die $err;
46 }
47  
48 8 ▶ 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 8 8
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
008
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i
l!l&&r!l&&!r
008
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i
l!l&&r!l&&!r
008
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 8 'Transient error on attempt %d/%d: %s. Retrying in %s seconds...',
60 $attempt, $max_retries, $err, $delay);
61 8 Time::HiRes::sleep($delay);
62 8 $delay *= $backoff_factor;
63 }
64 }
65  
66 17 1;
« blib/lib/Google/Auth/UserAuthorizer.pm ↑ Summary blib/lib/Google/Auth/WebUserAuthorizer.pm »