Skip to content

Commit 62269de

Browse files
committed
add smarter resumption scenario in integration tests
1 parent bea02a5 commit 62269de

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

google/cloud/storage/_experimental/asyncio/async_multi_range_downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ async def _do_open():
302302
self._routing_token = None
303303

304304
await self.read_obj_str.open(
305-
metadata=current_metadata if metadata else None
305+
metadata=current_metadata if current_metadata else None
306306
)
307307

308308
if self.read_obj_str.generation_number:

google/cloud/storage/_experimental/asyncio/retry/reads_resumption_strategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def update_state_from_response(
132132
read_state.is_complete = True
133133
if (
134134
read_state.initial_length != 0
135-
and read_state.bytes_written != read_state.initial_length
135+
and read_state.bytes_written > read_state.initial_length
136136
):
137137
raise DataCorruption(
138138
response,

tests/conformance/test_bidi_reads.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PROJECT_NUMBER = "12345" # A dummy project number is fine for the testbench.
1515
GRPC_ENDPOINT = "localhost:8888"
1616
HTTP_ENDPOINT = "http://localhost:9000"
17+
CONTENT_LENGTH = 1024 * 10 # 10 KB
1718

1819
def _is_retriable(exc):
1920
"""Predicate for identifying retriable errors."""
@@ -50,13 +51,13 @@ async def run_test_scenario(gapic_client, http_client, bucket_name, object_name,
5051
# 3. Execute the download and assert the outcome.
5152
try:
5253
await downloader.download_ranges(
53-
[(0, 4, buffer)], metadata=fault_injection_metadata
54+
[(0, 5 * 1024, buffer), (6 * 1024, 4 * 1024, buffer)], metadata=fault_injection_metadata
5455
)
5556
# If an exception was expected, this line should not be reached.
5657
if scenario['expected_error'] is not None:
5758
raise AssertionError(f"Expected exception {scenario['expected_error']} was not raised.")
5859

59-
assert buffer.getvalue() == b"This"
60+
assert len(buffer.getvalue()) == 9 * 1024
6061

6162
except scenario['expected_error'] as e:
6263
print(f"Caught expected exception for {scenario['name']}: {e}")
@@ -105,6 +106,12 @@ async def main():
105106
"instruction": "return-429",
106107
"expected_error": None,
107108
},
109+
{
110+
"name": "Smarter Resumption: Retry 503 after partial data",
111+
"method": "storage.objects.get",
112+
"instruction": "return-broken-stream-after-2K",
113+
"expected_error": None,
114+
},
108115
{
109116
"name": "Retry on BidiReadObjectRedirectedError",
110117
"method": "storage.objects.get",
@@ -115,13 +122,14 @@ async def main():
115122

116123
try:
117124
# Create a single bucket and object for all tests to use.
125+
content = b"A" * CONTENT_LENGTH
118126
bucket_resource = storage_v2.Bucket(project=f"projects/{PROJECT_NUMBER}")
119127
create_bucket_request = storage_v2.CreateBucketRequest(parent="projects/_", bucket_id=bucket_name, bucket=bucket_resource)
120128
await gapic_client.create_bucket(request=create_bucket_request)
121129

122130
write_spec = storage_v2.WriteObjectSpec(resource=storage_v2.Object(bucket=f"projects/_/buckets/{bucket_name}", name=object_name))
123131
async def write_req_gen():
124-
yield storage_v2.WriteObjectRequest(write_object_spec=write_spec, checksummed_data={"content": b"This is test data"}, finish_write=True)
132+
yield storage_v2.WriteObjectRequest(write_object_spec=write_spec, checksummed_data={"content": content}, finish_write=True)
125133
await gapic_client.write_object(requests=write_req_gen())
126134

127135
# Run all defined test scenarios.
@@ -196,9 +204,9 @@ async def run_open_test_scenario(gapic_client, http_client, bucket_name, object_
196204

197205
# If open was successful, perform a simple download to ensure the stream is usable.
198206
buffer = io.BytesIO()
199-
await downloader.download_ranges([(0, 4, buffer)])
207+
await downloader.download_ranges([(0, 1024, buffer)])
200208
await downloader.close()
201-
assert buffer.getvalue() == b"This"
209+
assert len(buffer.getvalue()) == 1024
202210

203211
# If an exception was expected, this line should not be reached.
204212
if scenario['expected_error'] is not None:

0 commit comments

Comments
 (0)