Skip to content

test(internal/bufferedread): fix flaky TestReadAtBackwardSeekIsRandomRead#4791

Merged
kislaykishore merged 1 commit into
masterfrom
fix-flaky-buffered-reader-test
Jun 19, 2026
Merged

test(internal/bufferedread): fix flaky TestReadAtBackwardSeekIsRandomRead#4791
kislaykishore merged 1 commit into
masterfrom
fix-flaky-buffered-reader-test

Conversation

@kislaykishore

@kislaykishore kislaykishore commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR resolves a flaky test failure in TestReadAtBackwardSeekIsRandomRead under the internal/bufferedread package.

Problem:
During a backward seek, ReadAt triggers a "fresh start" of prefetching, scheduling the first block urgently and subsequent prefetch blocks (blocks 1 and 2) asynchronously on the worker pool. Since the read request (1024 bytes) was satisfied entirely by block 0, ReadAt returned immediately. The test then immediately asserted the mock expectations. Because the prefetch tasks for blocks 1 and 2 were running asynchronously in the background, they did not always execute before AssertExpectations was called, causing flaky mock expectation failures.

Solution:
Synchronized the test by waiting for the asynchronous prefetch tasks to complete before asserting mock expectations. We pop the block queue entries for the two prefetched blocks (block 1 and block 2) and call AwaitReady(t.ctx) to block until their download tasks finish. This is an established pattern used in other tests in the same file (e.g., TestReadAtForwardSeekDiscardsPreviousBlocks).

Link to the issue in case of a bug fix.

b/525677881

Testing details

  1. Manual - Ran go test -v ./internal/bufferedread -run TestBufferedReaderTestSuite/TestReadAtBackwardSeekIsRandomRead multiple times to ensure it compiles and passes consistently.
  2. Unit tests - Executed the entire internal/bufferedread test suite successfully: go test -v ./internal/bufferedread.
  3. Integration tests - N/A

Any backward incompatible change? If so, please explain.

No

@kislaykishore kislaykishore marked this pull request as ready for review June 19, 2026 09:35
@kislaykishore kislaykishore requested a review from a team as a code owner June 19, 2026 09:35
@kislaykishore kislaykishore requested a review from geertj June 19, 2026 09:35
@github-actions github-actions Bot added the remind-reviewers Auto remind reviewers in attention set for review post 24hrs of inactivity on PR. label Jun 19, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses a flaky test failure within the internal/bufferedread package. By synchronizing the test execution to wait for background prefetch tasks to finish, the change ensures that mock expectations are asserted only after all expected operations have completed, thereby improving test reliability and consistency.

Highlights

  • Test Flakiness Resolution: Resolved a race condition in TestReadAtBackwardSeekIsRandomRead by ensuring asynchronous prefetch tasks complete before asserting mock expectations.
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 the 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 counterproductive. 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.

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.

@kislaykishore kislaykishore requested a review from vipnydav June 19, 2026 09:35

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

Copy link
Copy Markdown
Contributor

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 updates the TestReadAtBackwardSeekIsRandomRead test in internal/bufferedread/buffered_reader_test.go to pop prefetched blocks from the queue and await their readiness. This ensures that asynchronous prefetch tasks complete before verifying mock expectations, preventing potential race conditions in the test. There are no review comments to evaluate, and I have no additional feedback to provide.

@kislaykishore kislaykishore enabled auto-merge (squash) June 19, 2026 09:36

@abhishek10004 abhishek10004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving based on Vipin's review.

@kislaykishore kislaykishore merged commit 132c421 into master Jun 19, 2026
20 checks passed
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.65%. Comparing base (5ebd52d) to head (9d6dc6c).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4791      +/-   ##
==========================================
- Coverage   83.66%   83.65%   -0.01%     
==========================================
  Files         168      168              
  Lines       20850    20850              
==========================================
- Hits        17444    17442       -2     
- Misses       2755     2756       +1     
- Partials      651      652       +1     
Flag Coverage Δ
unittests 83.65% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

remind-reviewers Auto remind reviewers in attention set for review post 24hrs of inactivity on PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants