Skip to content

test(fix flaky test): fixing flaky TestZonalFileCacheReaderTestSuite#4788

Open
raj-prince wants to merge 2 commits into
masterfrom
flaky_zonal_file_cache
Open

test(fix flaky test): fixing flaky TestZonalFileCacheReaderTestSuite#4788
raj-prince wants to merge 2 commits into
masterfrom
flaky_zonal_file_cache

Conversation

@raj-prince

@raj-prince raj-prince commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Problem: The TestZonalFileCacheReaderTestSuite/Test_ReadAt_SequentialRangeRead test was flaky because the asynchronous background downloader goroutines (downloader.Job) were being leaked after each test completed. When TearDownTest() executed os.RemoveAll(t.cacheDir), it raced against those active background jobs trying to write to that same directory, causing device or resource busy or mock assertion failures.
  • Solution: Updated TearDownTest in file_cache_reader_test.go
    to call t.jobManager.Destroy() before removing the directory. This guarantees that all background downloader jobs are instantly cancelled and stopped, releasing their file descriptors and terminating their goroutines, making the directory cleanup completely safe and race-free.

Link to the issue in case of a bug fix.

b/524993281

Testing details

  1. Manual - yes, by running 30 times.
  2. Unit tests - NA
  3. Integration tests - NA

Any backward incompatible change? If so, please explain.

@raj-prince raj-prince marked this pull request as ready for review June 17, 2026 14:53
@raj-prince raj-prince requested a review from a team as a code owner June 17, 2026 14:53
@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 flakiness in the TestZonalFileCacheReaderTestSuite caused by race conditions between background downloader goroutines and test directory cleanup. By reordering the teardown sequence to ensure all asynchronous jobs are cancelled before the cache directory is removed, the tests are now more robust and reliable.

Highlights

  • Test Stability: Resolved a race condition in TestZonalFileCacheReaderTestSuite by ensuring background downloader jobs are properly terminated before directory cleanup.
  • Resource Management: Updated TearDownTest to explicitly call Destroy() on the job manager and readers, preventing goroutine leaks and file descriptor conflicts.
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.

@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 17, 2026

@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 TearDownTest method in file_cache_reader_test.go to clean up resources by calling .Destroy() on reader, reader_unfinalized_object, and jobManager before removing the cache directory. The review feedback recommends adding defensive nil checks before calling .Destroy() on these fields to prevent potential nil pointer dereference panics if SetupTest fails or panics before they are fully initialized.

Comment thread internal/gcsx/file_cache_reader_test.go Outdated
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.66%. Comparing base (bb135f3) to head (f54f73e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4788      +/-   ##
==========================================
- Coverage   83.66%   83.66%   -0.01%     
==========================================
  Files         168      168              
  Lines       20819    20819              
==========================================
- Hits        17419    17418       -1     
- Misses       2750     2751       +1     
  Partials      650      650              
Flag Coverage Δ
unittests 83.66% <ø> (-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.

1 participant