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): mustUpdateObject does not fail on precondition failure #10516

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test(storage): mustUpdateObject does not fail on precondition failure
  • Loading branch information
BrennaEpp committed Jul 6, 2024
commit dca9afc0777a3ea663694fd0fcc3caa548d25067
11 changes: 11 additions & 0 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5918,10 +5918,14 @@ func (h testHelper) mustDeleteObject(o *ObjectHandle) {
}

// updating an object is conditionally idempotent on metageneration, so we pass that in to enable retries
// mustUpdateObject will assume success if it receives a failed precondition response.
func (h testHelper) mustUpdateObject(o *ObjectHandle, ua ObjectAttrsToUpdate, metageneration int64) *ObjectAttrs {
h.t.Helper()
attrs, err := o.If(Conditions{MetagenerationMatch: metageneration}).Update(context.Background(), ua)
if err != nil {
if errorIsStatusCode(err, http.StatusPreconditionFailed, codes.FailedPrecondition) {
h.t.Logf("update object %q from bucket %q failed due to precondition, assuming success", o.ObjectName(), o.BucketName())
}
h.t.Fatalf("update object %q from bucket %q: %v", o.ObjectName(), o.BucketName(), err)
}
return attrs
Expand Down Expand Up @@ -6312,6 +6316,13 @@ func extractErrCode(err error) int {
return -1
}

func errorIsStatusCode(err error, httpStatusCode int, grpcStatusCode codes.Code) bool {
var httpErr *googleapi.Error
var grpcErr *apierror.APIError
return (errors.As(err, &httpErr) && httpErr.Code == httpStatusCode) ||
(errors.As(err, &grpcErr) && grpcErr.GRPCStatus().Code() == grpcStatusCode)
}

func setUpRequesterPaysBucket(ctx context.Context, t *testing.T, bucket, object string, addOwnerEmail string) {
t.Helper()
client := testConfig(ctx, t)
Expand Down
Loading