Skip to content

Commit

Permalink
test(storage): add retry for acl propagation to requesterpays test (#…
Browse files Browse the repository at this point in the history
…6604)

Co-authored-by: Chris Cotter <cjcotter@google.com>
  • Loading branch information
BrennaEpp and tritone committed Sep 1, 2022
1 parent 3bc37e2 commit e42772c
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions storage/integration_test.go
Expand Up @@ -3016,8 +3016,8 @@ func TestIntegration_RequesterPays(t *testing.T) {
} else if err == nil && !test.expectSuccess {
t.Errorf("%s: got unexpected success\n\t\t%s", desc, printTestCase())
} else if !test.expectSuccess && test.wantErrorCode != 0 && errCode(err) != test.wantErrorCode {
t.Errorf("%s: mismatched errors; %s\n\t\twant error code: %d\n\t\tgot error: %v\n",
desc, printTestCase(), test.wantErrorCode, err)
t.Errorf("%s: mismatched errors; want error code: %d, got error: %v \n\t\t%s\n",
desc, test.wantErrorCode, err, printTestCase())
}
}

Expand All @@ -3029,9 +3029,7 @@ func TestIntegration_RequesterPays(t *testing.T) {
if err := requesterPaysBucket.ACL().Set(ctx, ACLEntity("user-"+otherUserEmail), RoleOwner); err != nil {
t.Fatalf("set ACL: %v", err)
}
t.Cleanup(func() {
h.mustDeleteBucket(requesterPaysBucket)
})
t.Cleanup(func() { h.mustDeleteBucket(requesterPaysBucket) })

// Make sure the object exists, so we don't get confused by ErrObjectNotExist.
// The later write we perform may fail so we always write to the object as the user
Expand All @@ -3057,24 +3055,33 @@ func TestIntegration_RequesterPays(t *testing.T) {
}
}

// Object operations (except for delete)
checkforErrors("write object", writeObject(ctx, bucket.Object(objectName), "text/plain", []byte("hello")))
_, err = readObject(ctx, bucket.Object(objectName))
checkforErrors("read object", err)
_, err = bucket.Object(objectName).Attrs(ctx)
checkforErrors("get object attrs", err)
_, err = bucket.Object(objectName).Update(ctx, ObjectAttrsToUpdate{ContentLanguage: "en"})
checkforErrors("update object", err)

// Bucket ACL operations
// We interleave buckets to get around the rate limit
entity := ACLEntity("domain-google.com")

checkforErrors("bucket acl set", bucket.ACL().Set(ctx, entity, RoleReader))
_, err = bucket.ACL().List(ctx)
checkforErrors("bucket acl list", err)
checkforErrors("bucket acl delete", bucket.ACL().Delete(ctx, entity))

// Object operations (except for delete)
// Retry to account for propagation delay to objects in metadata update
// (we updated the metadata to add the otherUserEmail as owner on the bucket)
o := bucket.Object(objectName)
ctxWithTimeout, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()
// Only retry when we expect success to avoid retrying for 10 seconds
// when we know it will fail
if test.expectSuccess {
o = o.Retryer(WithErrorFunc(retryOnTransient400and403))
}
checkforErrors("write object", writeObject(ctxWithTimeout, o, "text/plain", []byte("hello")))
_, err = readObject(ctx, bucket.Object(objectName))
checkforErrors("read object", err)
_, err = bucket.Object(objectName).Attrs(ctx)
checkforErrors("get object attrs", err)
_, err = bucket.Object(objectName).Update(ctx, ObjectAttrsToUpdate{ContentLanguage: "en"})
checkforErrors("update object", err)

// Object ACL operations
checkforErrors("object acl set", bucket.Object(objectName).ACL().Set(ctx, entity, RoleReader))
_, err = bucket.Object(objectName).ACL().List(ctx)
Expand Down

0 comments on commit e42772c

Please sign in to comment.