Skip to content

Commit

Permalink
Added tests for isAppEngineRetryableError (#4470) (#8409)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Feb 8, 2021
1 parent 58bdfb9 commit 4471071
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/4470.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
appengine: added retry for P4SA propagation delay
```
2 changes: 1 addition & 1 deletion google/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func isAppEngineRetryableError(err error) (bool, string) {
if gerr.Code == 409 && strings.Contains(strings.ToLower(gerr.Body), "operation is already in progress") {
return true, "Waiting for other concurrent App Engine changes to finish"
}
if gerr.Code == 404 && strings.Contains(strings.ToLower(gerr.Body), "unable to retrieve P4SA") {
if gerr.Code == 404 && strings.Contains(strings.ToLower(gerr.Body), "unable to retrieve p4sa") {
return true, "Waiting for P4SA propagation to GAIA"
}
}
Expand Down
51 changes: 51 additions & 0 deletions google/error_retry_predicates_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package google

import (
"testing"

"google.golang.org/api/googleapi"
)

func TestIsAppEngineRetryableError_operationInProgress(t *testing.T) {
err := googleapi.Error{
Code: 409,
Body: "Operation is already in progress",
}
isRetryable, _ := isAppEngineRetryableError(&err)
if !isRetryable {
t.Errorf("Error not detected as retryable")
}
}

func TestIsAppEngineRetryableError_p4saPropagation(t *testing.T) {
err := googleapi.Error{
Code: 404,
Body: "Unable to retrieve P4SA: [[email protected]] from GAIA. Could be GAIA propagation delay or request from deleted apps.",
}
isRetryable, _ := isAppEngineRetryableError(&err)
if !isRetryable {
t.Errorf("Error not detected as retryable")
}
}

func TestIsAppEngineRetryableError_missingPage(t *testing.T) {
err := googleapi.Error{
Code: 404,
Body: "Missing page",
}
isRetryable, _ := isAppEngineRetryableError(&err)
if isRetryable {
t.Errorf("Error incorrectly detected as retryable")
}
}

func TestIsAppEngineRetryableError_serverError(t *testing.T) {
err := googleapi.Error{
Code: 500,
Body: "Unable to retrieve P4SA because of a bad thing happening",
}
isRetryable, _ := isAppEngineRetryableError(&err)
if isRetryable {
t.Errorf("Error incorrectly detected as retryable")
}
}

0 comments on commit 4471071

Please sign in to comment.