-
Notifications
You must be signed in to change notification settings - Fork 172
feat: Add system test for cross-region buckets #1760
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
base: lint_changes
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |||||
| # TODO: replace this with a fixture once zonal bucket creation / deletion | ||||||
| # is supported in grpc client or json client client. | ||||||
| _ZONAL_BUCKET = os.getenv("ZONAL_BUCKET") | ||||||
| _CROSS_REGION_BUCKET = os.getenv("CROSS_REGION_BUCKET") | ||||||
| _BYTES_TO_UPLOAD = b"dummy_bytes_to_write_read_and_delete_appendable_object" | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -82,6 +83,51 @@ def _get_equal_dist(a: int, b: int) -> tuple[int, int]: | |||||
| return a + step, a + 2 * step | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.parametrize( | ||||||
| "object_size", | ||||||
| [ | ||||||
| 256, # less than _chunk size | ||||||
| 10 * 1024 * 1024, # less than _MAX_BUFFER_SIZE_BYTES | ||||||
| 20 * 1024 * 1024, # greater than _MAX_BUFFER_SIZE | ||||||
| ], | ||||||
| ) | ||||||
| def test_basic_wrd_x_region( | ||||||
| storage_client, | ||||||
| blobs_to_delete, | ||||||
| object_size, | ||||||
| event_loop, | ||||||
| grpc_client, | ||||||
| ): | ||||||
|
Comment on lines
+94
to
+100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new test To improve maintainability, consider refactoring this to avoid duplication. One approach would be to parameterize a single test function to handle both zonal and cross-region bucket cases, as well as the direct path option. For example, you could parameterize on a tuple containing |
||||||
| object_name = f"test_basic_wrd-{str(uuid.uuid4())}" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For easier debugging and to avoid potential conflicts, it's good practice to make test object names specific to the test case. This helps identify which test created an object if cleanup fails.
Suggested change
|
||||||
|
|
||||||
| async def _run(): | ||||||
| object_data = os.urandom(object_size) | ||||||
| object_checksum = google_crc32c.value(object_data) | ||||||
|
|
||||||
| writer = AsyncAppendableObjectWriter(grpc_client, _CROSS_REGION_BUCKET, object_name) | ||||||
| await writer.open() | ||||||
| await writer.append(object_data) | ||||||
| object_metadata = await writer.close(finalize_on_close=True) | ||||||
| assert object_metadata.size == object_size | ||||||
| assert int(object_metadata.checksums.crc32c) == object_checksum | ||||||
|
|
||||||
| buffer = BytesIO() | ||||||
| mrd = AsyncMultiRangeDownloader(grpc_client, _CROSS_REGION_BUCKET, object_name) | ||||||
| async with mrd: | ||||||
| assert mrd._open_retries == 1 | ||||||
| # (0, 0) means read the whole object | ||||||
| await mrd.download_ranges([(0, 0, buffer)]) | ||||||
| assert mrd.persisted_size == object_size | ||||||
|
|
||||||
| assert buffer.getvalue() == object_data | ||||||
|
|
||||||
| # Clean up; use json client (i.e. `storage_client` fixture) to delete. | ||||||
| blobs_to_delete.append(storage_client.bucket(_CROSS_REGION_BUCKET).blob(object_name)) | ||||||
| del writer | ||||||
| gc.collect() | ||||||
|
|
||||||
| event_loop.run_until_complete(_run()) | ||||||
|
|
||||||
| @pytest.mark.parametrize( | ||||||
| "object_size", | ||||||
| [ | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will likely evaluate to
Noneas theCROSS_REGION_BUCKETenvironment variable is not exported in the test execution environment. Thecloudbuild.yamlconfiguration passes_CROSS_REGION_BUCKET, but therun_zonal_tests.shscript does not export it asCROSS_REGION_BUCKETfor thepytestcommand (unlikeZONAL_BUCKET).To fix this, you should add
export CROSS_REGION_BUCKET=${_CROSS_REGION_BUCKET}tocloudbuild/run_zonal_tests.sh. This change is necessary for the new test to pass.