Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(storage): add gRPC error code to retry to fix flaky PAP test #6974

Merged
merged 7 commits into from
Nov 1, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,16 @@ func TestIntegration_PublicAccessPrevention(t *testing.T) {

// Now, making object public or making bucket public should succeed. Run with
// retry because ACL settings may take time to propagate.
idempotentOrNilRetry := func(err error) bool {
return err == nil || ShouldRetry(err)
retrier := func(err error) bool {
// Once ACL settings propagate, PAP should no longer be enforced and the call will succeed.
// In the meantime, while PAP is enforced, trying to set ACL results in:
// - FailedPrecondition for gRPC
// - condition not met (412) for HTTP
return ShouldRetry(err) || status.Code(err) == codes.FailedPrecondition || extractErrCode(err) == http.StatusPreconditionFailed
}

ctxWithTimeout, cancelCtx := context.WithTimeout(ctx, time.Second*10)

a = o.Retryer(WithErrorFunc(idempotentOrNilRetry)).ACL()
a = o.Retryer(WithErrorFunc(retrier), WithPolicy(RetryAlways)).ACL()
err = a.Set(ctxWithTimeout, AllUsers, RoleReader)
cancelCtx()
if err != nil {
Expand Down Expand Up @@ -4832,3 +4835,16 @@ func skipGRPC(reason string) context.Context {
func skipHTTP(reason string) context.Context {
return context.WithValue(context.Background(), skipTransportTestKey("http"), reason)
}

// Extract the error code if it's a googleapi.Error
func extractErrCode(err error) int {
if err == nil {
return http.StatusOK
}
var e *googleapi.Error
if errors.As(err, &e) {
return e.Code
}

return -1
}