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

feat(storage): add retry config to the Client and HmacKey operations #5193

Merged
merged 15 commits into from Dec 20, 2021
2 changes: 1 addition & 1 deletion storage/emulator_test.sh
Expand Up @@ -58,7 +58,6 @@ trap cleanup EXIT
# TODO: move to passing once fixed
FAILING=( "buckets.setIamPolicy"
"objects.insert"
"hmacKey.update"
)
# TODO: remove regex once all tests are passing
# Unfortunately, there is no simple way to skip specific tests (see https://github.com/golang/go/issues/41583)
Expand All @@ -85,6 +84,7 @@ PASSING=( "buckets.list"
"hmacKey.list"
"hmacKey.create"
"hmacKey.delete"
"hmacKey.update"
"notifications.list"
"notifications.create"
"notifications.get"
Expand Down
13 changes: 7 additions & 6 deletions storage/hmac.go
Expand Up @@ -216,12 +216,12 @@ func (c *Client) CreateHMACKey(ctx context.Context, projectID, serviceAccountEma
setClientHeader(call.Header())

var hkPb *raw.HmacKey
var err error
err = run(ctx, func() error {
hkPb, err = call.Context(ctx).Do()

if err := run(ctx, func() error {
h, err := call.Context(ctx).Do()
hkPb = h
return err
}, c.retry, false)
if err != nil {
}, c.retry, false); err != nil {
return nil, err
}

Expand Down Expand Up @@ -263,10 +263,11 @@ func (h *HMACKeyHandle) Update(ctx context.Context, au HMACKeyAttrsToUpdate, opt

var metadata *raw.HmacKeyMetadata
var err error
isIdempotent := len(au.Etag) > 0
err = run(ctx, func() error {
metadata, err = call.Context(ctx).Do()
return err
}, h.retry, true)
}, h.retry, isIdempotent)

if err != nil {
return nil, err
Expand Down
14 changes: 10 additions & 4 deletions storage/retry_conformance_test.go
Expand Up @@ -252,12 +252,18 @@ var methods = map[string][]retryFunc{
"storage.hmacKey.update": {
func(ctx context.Context, c *Client, fs *resources, preconditions bool) error {
key := c.HMACKeyHandle(projectID, fs.hmacKey.AccessID)
uattrs := HMACKeyAttrsToUpdate{State: "INACTIVE"}

_, err := key.Update(ctx, HMACKeyAttrsToUpdate{State: "INACTIVE"})
if err != nil {
return err
if preconditions {
k, err := key.Get(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get Etag from fs.hmacKey rather than having another Get

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good note!

if err != nil {
return err
}
uattrs.Etag = k.Etag
}
return fmt.Errorf("Etag preconditions not supported")

_, err := key.Update(ctx, uattrs)
return err
},
},
"storage.objects.compose": {
Expand Down
4 changes: 2 additions & 2 deletions storage/storage_test.go
Expand Up @@ -875,9 +875,9 @@ func TestObjectRetryer(t *testing.T) {
}
}

// Test that Client.Retryer correctly configures the retry configuration
// Test that Client.SetRetry correctly configures the retry configuration
// on the Client.
func TestClientRetryer(t *testing.T) {
func TestClientSetRetry(t *testing.T) {
testCases := []struct {
name string
clientOptions []RetryOption
Expand Down