Migrate async client to unified checksum options#3
Conversation
There was a problem hiding this comment.
Code Review
This pull request transitions the asynchronous connection implementation and object descriptors to use the new UploadChecksumValidationOption and DownloadChecksumValidationOption instead of the deprecated EnableCrc32cValidationOption and EnableMD5ValidationOption. Feedback on the changes highlights several issues in the test suite, including redundant duplicate test cases and an incorrect test case expecting an invalid argument when validation is disabled. Additionally, the reviewer noted that the logic for resolving checksum validation options is duplicated across multiple non-test files, violating the repository style guide's recommendation to factor out code duplicated three or more times.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| HashTestCase{StatusCode::kOk, | ||
| Options{} | ||
| .set<storage::EnableCrc32cValidationOption>(true) | ||
| .set<storage::EnableMD5ValidationOption>(false), | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kCrc32c), | ||
| kQuickFoxCrc32cChecksum, kQuickFoxMD5HashBad}, | ||
| HashTestCase{StatusCode::kOk, | ||
| Options{} | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kMD5), | ||
| kQuickFoxCrc32cChecksumBad, kQuickFoxMD5Hash}, | ||
| HashTestCase{StatusCode::kOk, | ||
| Options{} | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kNone), | ||
| kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad}, |
| HashTestCase{StatusCode::kInvalidArgument, | ||
| Options{} | ||
| .set<storage::EnableCrc32cValidationOption>(false) | ||
| .set<storage::EnableMD5ValidationOption>(true), | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kMD5), | ||
| kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad}, | ||
| HashTestCase{StatusCode::kInvalidArgument, | ||
| Options{} | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kCrc32c), | ||
| kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad}, | ||
| HashTestCase{StatusCode::kInvalidArgument, | ||
| Options{} | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kNone), | ||
| kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad}, | ||
| HashTestCase{StatusCode::kInvalidArgument, | ||
| Options{} | ||
| .set<storage::EnableCrc32cValidationOption>(true) | ||
| .set<storage::EnableMD5ValidationOption>(false), | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kCrc32c), | ||
| kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad}, | ||
| HashTestCase{StatusCode::kInvalidArgument, | ||
| Options{} | ||
| .set<storage::EnableCrc32cValidationOption>(true) | ||
| .set<storage::EnableMD5ValidationOption>(true), | ||
| .set<storage::DownloadChecksumValidationOption>( | ||
| storage::ChecksumAlgorithm::kMD5), | ||
| kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad}, |
There was a problem hiding this comment.
This block of kInvalidArgument test cases contains several issues:
- The test case with
storage::ChecksumAlgorithm::kNone(lines 208-212) expectsStatusCode::kInvalidArgument. However, when validation is disabled (kNone), no validation is performed, so it should succeed withStatusCode::kOk(which is already tested in thekOksection). This test case is incorrect and will fail. - The test cases for
kCrc32candkMD5are duplicated (lines 213-217 and 218-222 are duplicates of lines 203-207 and 198-202 respectively).
Please simplify this block to only include the two unique and correct test cases for kMD5 and kCrc32c validation failures.
HashTestCase{StatusCode::kInvalidArgument,
Options{}
.set<storage::DownloadChecksumValidationOption>(
storage::ChecksumAlgorithm::kMD5),
kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad},
HashTestCase{StatusCode::kInvalidArgument,
Options{}
.set<storage::DownloadChecksumValidationOption>(
storage::ChecksumAlgorithm::kCrc32c),
kQuickFoxCrc32cChecksumBad, kQuickFoxMD5HashBad},| bool enable_crc32c = false; | ||
| bool enable_md5 = false; | ||
|
|
||
| if (options.has<storage::UploadChecksumValidationOption>()) { | ||
| auto const algo = options.get<storage::UploadChecksumValidationOption>(); | ||
| enable_crc32c = (algo == storage::ChecksumAlgorithm::kCrc32c); | ||
| enable_md5 = (algo == storage::ChecksumAlgorithm::kMD5); | ||
| } else { | ||
| enable_crc32c = options.get<storage::EnableCrc32cValidationOption>(); | ||
| enable_md5 = options.get<storage::EnableMD5ValidationOption>(); | ||
| } |
There was a problem hiding this comment.
The logic to resolve the checksum validation options is duplicated here and in CreateHashValidator (lines 132-142), as well as in object_descriptor_impl.cc. According to the repository style guide (lines 28-29), we should prefer to factor out duplicated code if it appears 3 or more times in non-test files. Consider defining a helper function template to handle both upload and download options:
template <typename Option>
std::pair<bool, bool> GetChecksumSettings(Options const& options) {
if (options.has<Option>()) {
auto const algo = options.get<Option>();
return {algo == storage::ChecksumAlgorithm::kCrc32c,
algo == storage::ChecksumAlgorithm::kMD5};
}
return {options.get<storage::EnableCrc32cValidationOption>(),
options.get<storage::EnableMD5ValidationOption>()};
}And then use structured bindings:
auto const [enable_crc32c, enable_md5] = GetChecksumSettings<storage::UploadChecksumValidationOption>(options);References
- Prefer to factor out duplicated code if it appears 3 or more times in non-test files. (link)
| bool enable_crc32c = false; | ||
| bool enable_md5 = false; | ||
| if (options_.has<storage::DownloadChecksumValidationOption>()) { | ||
| auto const algo = options_.get<storage::DownloadChecksumValidationOption>(); | ||
| enable_crc32c = (algo == storage::ChecksumAlgorithm::kCrc32c); | ||
| enable_md5 = (algo == storage::ChecksumAlgorithm::kMD5); | ||
| } else { | ||
| enable_crc32c = options_.get<storage::EnableCrc32cValidationOption>(); | ||
| enable_md5 = options_.get<storage::EnableMD5ValidationOption>(); | ||
| } |
There was a problem hiding this comment.
The logic to resolve the download checksum validation options is duplicated here and in CreateHashValidator (lines 266-275), as well as in connection_impl.cc. According to the repository style guide (lines 28-29), we should prefer to factor out duplicated code if it appears 3 or more times in non-test files. Consider factoring this out into a helper function (e.g., in an anonymous namespace or as a private helper method):
std::pair<bool, bool> GetDownloadChecksumSettings(Options const& options) {
if (options.has<storage::DownloadChecksumValidationOption>()) {
auto const algo = options.get<storage::DownloadChecksumValidationOption>();
return {algo == storage::ChecksumAlgorithm::kCrc32c,
algo == storage::ChecksumAlgorithm::kMD5};
}
return {options.get<storage::EnableCrc32cValidationOption>(),
options.get<storage::EnableMD5ValidationOption>()};
}And then use structured bindings:
auto const [enable_crc32c, enable_md5] = GetDownloadChecksumSettings(options_);References
- Prefer to factor out duplicated code if it appears 3 or more times in non-test files. (link)
1264fa0 to
55ceb4c
Compare
23658d1 to
bc369e7
Compare
55ceb4c to
6580fd9
Compare
bc369e7 to
9ed6fe1
Compare
9ed6fe1 to
2799489
Compare
6580fd9 to
6c92722
Compare
2799489 to
67305d6
Compare
67305d6 to
8bd3544
Compare
8bd3544 to
1268c7f
Compare
dc5fbb5 to
39c4a25
Compare
…d checksum helper
59e1bf1 to
c0cf77b
Compare
Migrates the Async client (
connection_impl.cc,object_descriptor_impl.cc) to use the newly introduced unified checksum options. Also includes the necessary fallback logic to support users who are still using the deprecated options.