-
-
Notifications
You must be signed in to change notification settings - Fork 171
fix: resolve flaky TestBatchExpiration/Process_Expire_Batch test #1413
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
Conversation
WalkthroughThe test Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes were found. Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.2.2)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@window9u Could you review this PR? |
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: 0
🧹 Nitpick comments (1)
pkg/limit/limiter_test.go (1)
360-369
: Fix parameter formatting.There's excessive whitespace in the function parameter list that affects readability.
- createCallbackWithTracking := func(o *occurs, chan struct{}) func() { + createCallbackWithTracking := func(o *occurs, completionChan chan struct{}) func() {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/limit/limiter_test.go
(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: hackerwins
PR: yorkie-team/yorkie#1224
File: test/bench/sync_only_load_bench_test.go:0-0
Timestamp: 2025-04-15T06:38:56.403Z
Learning: In the Yorkie project, benchmark tests that are very resource-intensive (like those creating many clients and connections) should be designed to run only once rather than using the standard Go benchmark iteration pattern with b.N.
pkg/limit/limiter_test.go (1)
Learnt from: hackerwins
PR: #1224
File: test/bench/sync_only_load_bench_test.go:0-0
Timestamp: 2025-04-15T06:38:56.403Z
Learning: In the Yorkie project, benchmark tests that are very resource-intensive (like those creating many clients and connections) should be designed to run only once rather than using the standard Go benchmark iteration pattern with b.N.
🔇 Additional comments (3)
pkg/limit/limiter_test.go (3)
376-379
: LGTM! Proper channel setup for callback tracking.The buffered channel with capacity
totalKeys*2
correctly accounts for both immediate and debounced callbacks, and the callback is properly wrapped with completion tracking.
393-401
: Excellent fix! Replaces timing assumptions with explicit synchronization.This change eliminates the flaky behavior by waiting for actual callback completion rather than relying on sleep timing. The timeout mechanism prevents hanging while providing clear error messages for debugging.
405-420
: Perfect solution to the flaky test issue!This implementation correctly addresses the root cause of test flakiness by:
- Waiting for actual callback execution rather than assuming timing
- Using appropriate timeouts to prevent hangs
- Providing clear error messages for debugging
- Only asserting counts after confirming callback completion
This eliminates the race conditions that were causing intermittent failures in CI.
@hackerwins Sure! I'll try to review it until this week! |
Co-authored-by: changhui lee <iam@xo.dev>
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.
Thank you for refactoring time.Sleep()
based test!
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.
Thanks for your contribution.
What this PR does / why we need it:
This PR fixes intermittent failures in the
TestBatchExpiration/Process_Expire_Batch
test that were causing CI noise and reducing developer confidence. The test was relying on fixed timing assumptions (time.Sleep
) which made it flaky in different CI environments.The solution replaces time-based waiting with channel-based synchronization to track actual callback completion, eliminating timing dependencies and race conditions.
Which issue(s) this PR fixes:
close #1412
Fixes # (CI flaky test issue)
Special notes for your reviewer:
createCallbackWithTracking
helper that uses channels to signal callback completionDoes this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit