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

tests: add retry conf s8 test cases and data integrity checks #702

Merged
merged 5 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
124 changes: 124 additions & 0 deletions tests/conformance/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import uuid

import pytest

from google.auth.credentials import AnonymousCredentials
from google.cloud import storage
from google.cloud.exceptions import NotFound


"""Environment variable or default host for Storage testbench emulator."""
_HOST = os.environ.get("STORAGE_EMULATOR_HOST", "http://localhost:9000")


"""Emulated project information for the storage testbench."""
_CONF_TEST_PROJECT_ID = "my-project-id"
_CONF_TEST_SERVICE_ACCOUNT_EMAIL = (
"[email protected]"
)
_CONF_TEST_PUBSUB_TOPIC_NAME = "my-topic-name"

"""Create content payload in different sizes."""


def _create_block(desired_kib):
line = "abc123XYZ" * 14 + "!" + "\n"
return 1024 * int(desired_kib / len(line)) * line


_STRING_CONTENT = "hello world"
_SIZE_16MB = 16384 # 16*1024 KiB


########################################################################################################################################
### Pytest Fixtures to Populate Retry Conformance Test Resources #######################################################################
########################################################################################################################################


@pytest.fixture
def client():
client = storage.Client(
project=_CONF_TEST_PROJECT_ID,
credentials=AnonymousCredentials(),
client_options={"api_endpoint": _HOST},
)
return client


@pytest.fixture
def bucket(client):
bucket = client.bucket(uuid.uuid4().hex)
client.create_bucket(bucket)
yield bucket
try:
bucket.delete(force=True)
except NotFound: # in cases where bucket is deleted within the test
pass


@pytest.fixture
def object(client, bucket):
blob = client.bucket(bucket.name).blob(uuid.uuid4().hex)
blob.upload_from_string(_STRING_CONTENT)
blob.reload()
yield blob
try:
blob.delete()
except NotFound: # in cases where object is deleted within the test
pass


@pytest.fixture
def notification(client, bucket):
notification = client.bucket(bucket.name).notification(
topic_name=_CONF_TEST_PUBSUB_TOPIC_NAME
)
notification.create()
notification.reload()
yield notification
try:
notification.delete()
except NotFound: # in cases where notification is deleted within the test
pass


@pytest.fixture
def hmac_key(client):
hmac_key, _secret = client.create_hmac_key(
service_account_email=_CONF_TEST_SERVICE_ACCOUNT_EMAIL,
project_id=_CONF_TEST_PROJECT_ID,
)
yield hmac_key
try:
hmac_key.state = "INACTIVE"
hmac_key.update()
hmac_key.delete()
except NotFound: # in cases where hmac_key is deleted within the test
pass


@pytest.fixture
def file_data(client, bucket):
blob = client.bucket(bucket.name).blob(uuid.uuid4().hex)
payload = _create_block(_SIZE_16MB)
blob.upload_from_string(payload)
yield blob, payload
try:
blob.delete()
except NotFound: # in cases where object is deleted within the test
pass
25 changes: 25 additions & 0 deletions tests/conformance/retry_strategy_test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,31 @@
],
"preconditionProvided": true,
"expectSuccess": false
},
{
"id": 7,
"description": "resumable_uploads_handle_complex_retries",
"cases": [],
"methods": [],
"preconditionProvided": true,
"expectSuccess": true
},
{
"id": 8,
"description": "downloads_handle_complex_retries",
"cases": [
{
"instructions": ["return-broken-stream", "return-broken-stream"]
},
{
"instructions": ["return-broken-stream-after-256K"]
}
],
"methods": [
{"name": "storage.objects.get", "group": "storage.objects.download", "resources": ["BUCKET", "OBJECT"]}
],
"preconditionProvided": false,
"expectSuccess": true
}
]
}
Loading