Skip to content

Commit

Permalink
test(storage): add gRPC error code to retry to fix flaky PAP test (#6974
Browse files Browse the repository at this point in the history
)
  • Loading branch information
BrennaEpp committed Nov 1, 2022
1 parent f7c7f41 commit e7ab70b
Showing 1 changed file with 20 additions and 4 deletions.
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 @@ -4872,3 +4875,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 0
}
var e *googleapi.Error
if errors.As(err, &e) {
return e.Code
}

return -1
}

0 comments on commit e7ab70b

Please sign in to comment.