Repository navigation
test(storage): cover zero-copy BidiReadObject reads in the Rapid system tests - #18980
Merged
Merged
Conversation
Exercise the opt-in zero-copy BidiReadObjectResponse parser (GCS_PYTHON_CLIENT_ZERO_COPY_BIDI_READ=1) against a Rapid bucket over a single AsyncMultiRangeDownloader stream: zero-copy RPC selection, bytes chunks for default write() destinations, memoryview chunks with accepts_memoryview=True when google-crc32c accepts memoryview, multi-message reads into bytearray and writable memoryview buffers with guard bytes, and BufferError on a read clamped at EOF without closing the stream.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a new system test, test_mrd_zero_copy_bidi_read, to verify zero-copy BidiReadObject reads across write and buffer destinations. The feedback suggests improving the test's code quality by using isinstance for type checking to remain idiomatic and consistent, removing a redundant assertion on exc_info.tb after a pytest.raises block, and deleting unnecessary del writer and gc.collect() calls that could potentially raise a NameError if the gc module is not imported.
Contributor
Author
|
/gcbrun |
…ser and accepts_memoryview on and off
Contributor
Author
|
/gcbrun |
…ystem-tests # Conflicts: # packages/google-cloud-storage/tests/system/test_rapid.py
Contributor
Author
|
/gcbrun |
Contributor
Author
|
CI should be fixed by #18981 |
chandra-siri
approved these changes
Nov 4, 2026
Contributor
|
/gcbrun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Rapid system tests for the opt-in zero-copy
BidiReadObjectResponseparser (GCS_PYTHON_CLIENT_ZERO_COPY_BIDI_READ=1) from #18627, as requested in its review:test_mrd_zero_copy_bidi_read, a new test for behavior specific to the parser: chunk types, buffer destinations and short reads.tests/system/test_rapid.pythat callsdownload_rangesnow runs with the parser off and on, and withaccepts_memoryviewset toFalseandTrue.They run with the existing Rapid system tests (and in manual RCU runs); no CI changes.
test_mrd_zero_copy_bidi_readThe test writes one 5 MiB appendable object, finalizes it, and reads it back over a single
AsyncMultiRangeDownloaderstream with the parser enabled:BidiReadObjectRPC, and the downloader still gets the object size from the open response.write()destination receives onlybyteschunks.download_ranges(..., accepts_memoryview=True), chunks arememoryviews when the installedgoogle-crc32cacceptsmemoryviewandbytesotherwise (for examplegoogle-crc32c1.9.0). The chunks kept after the call still match the object data.download_rangescall fills abytearrayand a writablememoryviewslice of a larger buffer, 2.5 MiB each. Guard bytes around the slice catch out-of-range writes, and both buffers are cleared afterwards, which fails if the SDK kept a view of either one.BufferErrorand leaves the stream open. The buffer is cleared while the exception is still held, which checks that the SDK released its view itself, and the next read on the same downloader succeeds.Existing read tests
Two new fixtures:
zero_copy_bidi_readsetsGCS_PYTHON_CLIENT_ZERO_COPY_BIDI_READto0or1throughmonkeypatch, so nothing leaks into later tests on the shared session-scoped gRPC client, andaccepts_memoryviewis passed to everydownload_rangescall. The 14 tests that calldownload_rangestake both, on top of theirmulti_stream_configparameter from #18537, so each runs in eight combinations: those tests go from 62 to 248 cases and the file from 73 to 260.test_mrd_zero_copy_bidi_readkeeps its own settings. In thepython-sdk-zb-system-testcheck, pytest takes 156 s instead of 47 s onmain(252 passed; the 8 skipped cases are the read-handle test, which was already skipped).Testing
I ran the new test locally against an in-process
grpc.aioserver implementingBidiWriteObjectandBidiReadObject(responses of at most 2 MiB, with and without an empty final response on a 2 MiB boundary), once withgoogle-crc32c1.9.0 and once with agoogle-crc32cbuild frommainthat acceptsmemoryview. Against the same server I ran the 10 parametrized tests it can serve in all their combinations, including bothmulti_stream_configvalues, checking that each stream used the expected parser and each call passed the expectedaccepts_memoryview; the cross-region, write-handle and append-to-existing-object tests need a real bucket, and the read-handle test is skipped. Thepython-sdk-zb-system-testcheck runs everything against a real Rapid bucket.