-
Notifications
You must be signed in to change notification settings - Fork 339
test: add unit tests for Debouncer utility #705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
test: add unit tests for Debouncer utility #705
Conversation
|
🎉 Welcome @DEVANSH-GAJJAR!
We appreciate your contribution! 🚀 |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughAdded three ignore patterns to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In @test/utils/debouncer.dart:
- Around line 6-17: The test "executes action after debounce duration" uses
Debouncer(milliseconds: 50) but only awaits Future.delayed(const
Duration(milliseconds: 60)), which is a tight 10ms buffer and can flake;
increase the delay to a safer value (e.g., 100ms or 150ms) in the Future.delayed
call so the debounced callback has ample time to run reliably in CI and slow
environments.
- Around line 19-34: The test "cancels previous action when run is called again"
uses a 50ms Debouncer and only awaits 60ms which is a small 10ms buffer and can
be flaky in CI; update the test in test/utils/debouncer.dart to increase the
post-run wait (e.g., await Future.delayed(const Duration(milliseconds: 100)) or
similar) so there is a safe margin beyond Debouncer(milliseconds: 50), keeping
the Debouncer instantiation and test logic (count, debouncer.run calls, expect)
unchanged.
- Around line 36-49: The test "dispose cancels pending action" uses a 50ms
Debouncer and only waits 60ms before asserting, which is flaky; increase the
post-dispose wait to a larger buffer (e.g., change Future.delayed(const
Duration(milliseconds: 60)) to at least 100–150ms or to (debouncer milliseconds
+ 50–100ms)) so the environment scheduling variance is covered; keep the test
logic and expect(called, false) unchanged and reference the Debouncer class and
the test name when making the change.
🧹 Nitpick comments (2)
.gitignore (1)
56-58: Consider simplifying the build directory ignore patterns.The pattern
build/on line 56 already matches build directories at any level in the repository tree, making the more specific patterns on lines 57-58 (test/build/andtest/utils/build/) redundant. You can remove lines 57-58 to simplify the configuration.♻️ Suggested simplification
build/ -test/build/ -test/utils/build/test/utils/debouncer.dart (1)
4-51: Good test coverage for core Debouncer functionality.The tests effectively cover the main debouncer behaviors: execution timing, cancellation, and disposal. The test structure is clear and assertions are appropriate.
For even more comprehensive coverage, you could optionally consider adding tests for edge cases such as:
- Multiple calls to
dispose()(idempotency)- Calling
run()afterdispose()- Verifying that
dispose()after the action has already executed is safe
|
Please open an issue for the PR and raise it to dev, not master |
|
Merge conflict resolved. Kept the dev branch version of CODEOWNERS and cleaned up the file. |
|
There are some unrelated commits in the PR, could you delete those please |
06b5269 to
678ca43
Compare
|
Thanks for pointing that out! |
|
Hi, I have resolved the merge conflicts, and removed the unrelated commits The PR is now clean and ready for review. Please let me know if any further changes are required. Thanks! |
Description
This PR adds unit tests for the
Debouncerutility to ensure correct timing, cancellation, and disposal behavior.Fixes #709
Type of change
Please delete options that are not relevant.
Command used:
flutter test test/utils/debouncer.dartHow Has This Been Tested?
Unit tests were added for the
Debouncerclass and executed locally using Flutter’s test runner.Checklist:
Maintainer Checklist
Summary by CodeRabbit
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.