Skip to content

Refactor grain_data_processing_test and improve time#3918

Merged
copybara-service[bot] merged 1 commit into
mainfrom
aireen/shorten_data_tests
May 18, 2026
Merged

Refactor grain_data_processing_test and improve time#3918
copybara-service[bot] merged 1 commit into
mainfrom
aireen/shorten_data_tests

Conversation

@aireenmei

@aireenmei aireenmei commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Description

As data pipeline unit tests in grain_data_processing_test.py grow, it take a lot of time from the CI runner. The base test includes three tests: test_train_ds, test_batch_determinism, test_for_loop_repeatable. And all the variants inherit these three test. Since it's unlikely for the config variants to change the determinism and for_loop_repeatable behavior, this PR refactor introduces _Grain{format}Setup, GrainBaseProcessingTest, GrainDeterminismMixin class, and have the config variant test only inherit _Grain{format}Setup and GrainBaseProcessingTest to reduce the time for running determinism tests.

Tests

When running locally (CI runner time will be different but expect similar percentage)
Before this PR, all tests in grain_data_processing_test.py takes 7:08 min, log
After this PR, all tests in grain_data_processing_test.py takes 4:15 min, log

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hi @aireenmei, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@github-actions github-actions 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.

## 📋 Review Summary

This PR successfully refactors grain_data_processing_test.py to improve test execution time. By introducing specialized mixins for setup and determinism, it avoids redundant and expensive checks in variant subclasses while actually increasing the validation depth for the primary format tests.

🔍 General Feedback

  • Refactoring Quality: The use of GrainDeterminismMixin and private setup mixins like _GrainArrayRecordSetup is a clean architectural improvement that makes the test suite more modular and maintainable.
  • Coverage: The addition of auxiliary tensor checks in the determinism tests is a proactive improvement to the overall test quality.
  • Performance: This change should significantly reduce the time spent in grain_data_processing_test.py during CI runs by eliminating redundant test_batch_determinism and test_for_loop_repeatable calls in specialized variant tests.

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.

🟢 This is a solid refactoring. Moving the determinism tests into a separate mixin (GrainDeterminismMixin) and setup logic into format-specific mixins (_GrainArrayRecordSetup, _GrainTFRecordSetup) effectively reduces redundant test execution in variant subclasses, which will significantly improve CI performance.

@codecov

codecov Bot commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@aireenmei
aireenmei force-pushed the aireen/shorten_data_tests branch 2 times, most recently from b3ec285 to 6c2949e Compare May 15, 2026 21:26
@aireenmei aireenmei changed the title Improve time for grain_data_processing_test Refactor grain_data_processing_test and improve time May 15, 2026
@aireenmei
aireenmei marked this pull request as ready for review May 15, 2026 21:33
Comment thread tests/unit/grain_data_processing_test.py Outdated
@aireenmei
aireenmei force-pushed the aireen/shorten_data_tests branch from 6c2949e to 1ab5b5b Compare May 15, 2026 21:48
@aireenmei
aireenmei force-pushed the aireen/shorten_data_tests branch from 1ab5b5b to feaf467 Compare May 15, 2026 21:49
@copybara-service
copybara-service Bot merged commit e835a6c into main May 18, 2026
81 of 83 checks passed
@copybara-service
copybara-service Bot deleted the aireen/shorten_data_tests branch May 18, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants