Skip to content

test(storage): add mrd test for negative offset and 0 length#13593

Open
krishnamd-jkp wants to merge 1 commit intogoogleapis:mainfrom
krishnamd-jkp:add_mrd_integ_test
Open

test(storage): add mrd test for negative offset and 0 length#13593
krishnamd-jkp wants to merge 1 commit intogoogleapis:mainfrom
krishnamd-jkp:add_mrd_integ_test

Conversation

@krishnamd-jkp
Copy link
Contributor

No description provided.

@krishnamd-jkp krishnamd-jkp requested a review from a team as a code owner January 13, 2026 16:31
@krishnamd-jkp krishnamd-jkp requested a review from a team January 13, 2026 16:31
@krishnamd-jkp krishnamd-jkp requested a review from a team as a code owner January 13, 2026 16:31
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @krishnamd-jkp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new integration test to enhance the robustness of the MultiRangeDownloader functionality. The added test specifically validates its behavior when handling edge cases involving negative offsets and zero-length read requests, ensuring correct data retrieval under these conditions and improving the overall reliability of the component.

Highlights

  • New Integration Test: A new integration test, TestIntegration_MRDWithNegativeOffsetsAndZeroLength, has been added to validate the MultiRangeDownloader's behavior.
  • Edge Case Coverage: This test specifically covers edge cases for the MultiRangeDownloader when dealing with negative offsets and zero-length read requests.
  • Comprehensive Test Scenarios: The test includes scenarios for positive offset/positive length, positive offset/zero length, negative offset/positive length, and negative offset/zero length to ensure robust handling of various range download requests.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an integration test for the Multi-Range Downloader (MRD) to verify its behavior with negative offsets and zero-length ranges. The test cases cover positive and negative offsets combined with positive and zero lengths.

My review focuses on improving the test's robustness and maintainability. I've suggested using a unique object name to prevent test conflicts and enhancing the assertions to be more comprehensive and provide better failure diagnostics. Overall, the new test is a valuable addition.

// Generate random content for testing.
content := make([]byte, dataSize)
rand.New(rand.NewSource(0)).Read(content)
objName := "MRDWithReadHandle"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid potential conflicts with other tests, it's good practice to use a unique object name for each test function. The current name MRDWithReadHandle is already used in TestIntegration_MRDWithReadHandle. Using a name specific to this test, like the test function name itself, will prevent flakes if tests are run in parallel against the same bucket.

Suggested change
objName := "MRDWithReadHandle"
objName := "MRDWithNegativeOffsetsAndZeroLength"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do this

Comment on lines +692 to +706
var startIdx, endIdx int
if test.offset < 0 {
startIdx = max(0, int(test.offset)+dataSize)
} else {
startIdx = int(test.offset)
}
if test.length == 0 {
endIdx = dataSize
} else {
endIdx = min(dataSize, startIdx+int(test.length))
}
wantContent := content[startIdx:endIdx]
if !bytes.Equal(res.buf.Bytes(), wantContent) {
t.Errorf("Downloaded content mismatch. got %v bytes, want %v bytes", res.buf.Bytes(), wantContent)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test's assertions can be improved. It's good practice to also verify the values returned by the onDone callback (offset, limit, and err) to ensure the downloader reports the correct effective range. Additionally, the error message for content mismatch could be more informative by printing the lengths of the byte slices and using %q for a more readable output.

				var startIdx, endIdx int
				if test.offset < 0 {
					startIdx = max(0, int(test.offset)+dataSize)
				} else {
					startIdx = int(test.offset)
				}
				if test.length == 0 {
					endIdx = dataSize
				} else {
					endIdx = min(dataSize, startIdx+int(test.length))
				}
				if res.err != nil {
					t.Fatalf("onDone callback returned an error: %v", res.err)
				}
				if res.offset != int64(startIdx) {
					t.Errorf("onDone offset: got %d, want %d", res.offset, startIdx)
				}
				if res.limit != int64(endIdx) {
					t.Errorf("onDone limit: got %d, want %d", res.limit, endIdx)
				}
				wantContent := content[startIdx:endIdx]
				if !bytes.Equal(res.buf.Bytes(), wantContent) {
					t.Errorf("Downloaded content mismatch. got len %d, want len %d.\ngot: %q\nwant: %q", res.buf.Len(), len(wantContent), res.buf.Bytes(), wantContent)
				}

@quartzmo quartzmo changed the title test: add mrd test for negative offset and 0 length storage: add mrd test for negative offset and 0 length Jan 13, 2026
@quartzmo quartzmo changed the title storage: add mrd test for negative offset and 0 length test(storage): add mrd test for negative offset and 0 length Jan 13, 2026
// Generate random content for testing.
content := make([]byte, dataSize)
rand.New(rand.NewSource(0)).Read(content)
objName := "MRDWithReadHandle"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do this

{
name: "negative offset zero length",
offset: -10,
length: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We take care of negative length right?

@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants