Skip to content

Commit 7f07f25

Browse files
Added tests for isAppEngineRetryableError (#4470) (#2938)
Signed-off-by: Modular Magician <[email protected]>
1 parent 3d8869d commit 7f07f25

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.changelog/4470.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
appengine: added retry for P4SA propagation delay
3+
```

google-beta/error_retry_predicates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func isAppEngineRetryableError(err error) (bool, string) {
246246
if gerr.Code == 409 && strings.Contains(strings.ToLower(gerr.Body), "operation is already in progress") {
247247
return true, "Waiting for other concurrent App Engine changes to finish"
248248
}
249-
if gerr.Code == 404 && strings.Contains(strings.ToLower(gerr.Body), "unable to retrieve P4SA") {
249+
if gerr.Code == 404 && strings.Contains(strings.ToLower(gerr.Body), "unable to retrieve p4sa") {
250250
return true, "Waiting for P4SA propagation to GAIA"
251251
}
252252
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package google
2+
3+
import (
4+
"testing"
5+
6+
"google.golang.org/api/googleapi"
7+
)
8+
9+
func TestIsAppEngineRetryableError_operationInProgress(t *testing.T) {
10+
err := googleapi.Error{
11+
Code: 409,
12+
Body: "Operation is already in progress",
13+
}
14+
isRetryable, _ := isAppEngineRetryableError(&err)
15+
if !isRetryable {
16+
t.Errorf("Error not detected as retryable")
17+
}
18+
}
19+
20+
func TestIsAppEngineRetryableError_p4saPropagation(t *testing.T) {
21+
err := googleapi.Error{
22+
Code: 404,
23+
Body: "Unable to retrieve P4SA: [[email protected]] from GAIA. Could be GAIA propagation delay or request from deleted apps.",
24+
}
25+
isRetryable, _ := isAppEngineRetryableError(&err)
26+
if !isRetryable {
27+
t.Errorf("Error not detected as retryable")
28+
}
29+
}
30+
31+
func TestIsAppEngineRetryableError_missingPage(t *testing.T) {
32+
err := googleapi.Error{
33+
Code: 404,
34+
Body: "Missing page",
35+
}
36+
isRetryable, _ := isAppEngineRetryableError(&err)
37+
if isRetryable {
38+
t.Errorf("Error incorrectly detected as retryable")
39+
}
40+
}
41+
42+
func TestIsAppEngineRetryableError_serverError(t *testing.T) {
43+
err := googleapi.Error{
44+
Code: 500,
45+
Body: "Unable to retrieve P4SA because of a bad thing happening",
46+
}
47+
isRetryable, _ := isAppEngineRetryableError(&err)
48+
if isRetryable {
49+
t.Errorf("Error incorrectly detected as retryable")
50+
}
51+
}

0 commit comments

Comments
 (0)