Skip to content

Commit 734101a

Browse files
authored
test(storage): fix flaky RequesterPays (#9082)
Add retry on 400 and 403 to object deletes
1 parent 16ecfd1 commit 734101a

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

storage/integration_test.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,6 @@ func TestIntegration_RequesterPaysNonOwner(t *testing.T) {
30753075
},
30763076
} {
30773077
t.Run(test.desc, func(t *testing.T) {
3078-
h := testHelper{t}
30793078
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
30803079
t.Cleanup(cancel)
30813080

@@ -3163,22 +3162,28 @@ func TestIntegration_RequesterPaysNonOwner(t *testing.T) {
31633162
checkforErrors("default object acl delete", bucket.DefaultObjectACL().Delete(ctx, entity))
31643163

31653164
// Copy
3166-
_, err = bucket.Object("copy").CopierFrom(bucket.Object(objectName)).Run(ctx)
3165+
copyObj := bucket.Object("copy")
3166+
_, err = copyObj.CopierFrom(bucket.Object(objectName)).Run(ctx)
31673167
checkforErrors("copy", err)
31683168
// Delete "copy" object, if created
31693169
if err == nil {
31703170
t.Cleanup(func() {
3171-
h.mustDeleteObject(bucket.Object("copy"))
3171+
if err := deleteObjectIfExists(copyObj, WithErrorFunc(retryOnTransient400and403)); err != nil {
3172+
t.Error(err)
3173+
}
31723174
})
31733175
}
31743176

31753177
// Compose
3176-
_, err = bucket.Object("compose").ComposerFrom(bucket.Object(objectName), bucket.Object("copy")).Run(ctx)
3178+
composeObj := bucket.Object("compose")
3179+
_, err = composeObj.ComposerFrom(bucket.Object(objectName), bucket.Object("copy")).Run(ctx)
31773180
checkforErrors("compose", err)
31783181
// Delete "compose" object, if created
31793182
if err == nil {
31803183
t.Cleanup(func() {
3181-
h.mustDeleteObject(bucket.Object("compose"))
3184+
if err := deleteObjectIfExists(composeObj, WithErrorFunc(retryOnTransient400and403)); err != nil {
3185+
t.Error(err)
3186+
}
31823187
})
31833188
}
31843189

@@ -5501,6 +5506,27 @@ func (h testHelper) mustRead(obj *ObjectHandle) []byte {
55015506
return data
55025507
}
55035508

5509+
// deleteObjectIfExists deletes an object with a RetryAlways policy (unless another
5510+
// policy is supplied in the options). It will not return an error if the object
5511+
// is already deleted/doesn't exist. It will time out after 15 seconds.
5512+
func deleteObjectIfExists(o *ObjectHandle, retryOpts ...RetryOption) error {
5513+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
5514+
defer cancel()
5515+
retryOpts = append([]RetryOption{WithPolicy(RetryAlways)}, retryOpts...)
5516+
5517+
if err := o.Retryer(retryOpts...).Delete(ctx); err != nil {
5518+
var apiErr *apierror.APIError
5519+
if ok := errors.As(err, &apiErr); ok {
5520+
// Object may already be deleted with retry; if so, return no error.
5521+
if apiErr.HTTPCode() == 404 || apiErr.GRPCStatus().Code() == codes.NotFound {
5522+
return nil
5523+
}
5524+
}
5525+
return fmt.Errorf("delete object %s from bucket %s: %v", o.ObjectName(), o.BucketName(), err)
5526+
}
5527+
return nil
5528+
}
5529+
55045530
func writeObject(ctx context.Context, obj *ObjectHandle, contentType string, contents []byte) error {
55055531
w := obj.Retryer(WithPolicy(RetryAlways)).NewWriter(ctx)
55065532
w.ContentType = contentType

0 commit comments

Comments
 (0)