Repository navigation
Fix flaky TestMultipleRecursiveFunctionsIndependent test - #1626
Conversation
The test was flaky because it relied on comparing execution times based on recursion depth. Without deterministic timing, the assertion that func1.Total > func2.Total was unreliable and would occasionally fail. Changes: - Remove time.Sleep calls from both recursive functions - Remove flaky timing comparison assertion - Add assertions to verify non-zero duration for both functions - Add assertion to verify both functions tracked independently in registry - Change func2 recursion depth from 25 to 10 (less overhead, still tests behavior) - Add clarifying comments about what behavior is being tested This fix is backported from PR #1621 which already addressed this issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
CodeRabbit (@coderabbitai) full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughRenamed and refactored a perf test: Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (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). (1)
🔇 Additional comments (4)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1626 +/- ##
==========================================
- Coverage 64.55% 64.53% -0.03%
==========================================
Files 334 334
Lines 37536 37536
==========================================
- Hits 24231 24222 -9
- Misses 11349 11355 +6
- Partials 1956 1959 +3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
The previous fix removed time.Sleep() but still checked for non-zero duration, which fails on Windows where the recursion executes so fast that duration is 0. The actual purpose of this test is to verify independent tracking of multiple functions, not to measure timing. The key assertions are: - Each function has count=1 (one top-level call) - Both functions are tracked separately in the registry Changes: - Remove non-zero duration assertions that fail on Windows - Add comment explaining why we don't check duration - Keep the essential assertions that verify independent tracking behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The previous approach removed duration checks entirely, but the test should verify that duration tracking actually works for multiple independent functions. The root cause of the Windows flakiness was that without any sleep, the recursion executes so fast that duration is 0, making the test fail. Solution: - Add minimal 1ms sleep in each function (NOT in the recursion loop) - This ensures measurable duration on all platforms including Windows - Restore the duration non-zero checks to verify tracking works correctly - Keep the test fast (~2ms total sleep time) This properly tests: 1. Independent tracking (count=1 for each function) 2. Separate registry entries (2 functions tracked) 3. Duration tracking works (non-zero duration for both) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The test was named TestMultipleRecursiveFunctionsIndependent but the recursion added unnecessary complexity without adding test value. The actual behavior being tested is that multiple functions track independently. Changes: - Remove recursion entirely - other tests already cover recursive tracking - Rename test to TestMultipleFunctionsTrackIndependently (clearer purpose) - Simplify to two simple functions that each sleep 1ms - Keep the essential assertions: count=1, separate registry entries, non-zero duration This is simpler, faster, and tests the actual intended behavior without the flaky timing comparisons that plagued the original recursive version. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
CodeRabbit (@coderabbitai) review |
✅ Actions performedReview triggered.
|
Resolved conflict in pkg/perf/perf_test.go by accepting main branch's version of TestMultipleFunctionsTrackIndependently, which already includes a stable fix for the flaky test. The main branch's fix (PR #1626) and our fixes addressed the same issue independently. Their approach is cleaner: - Uses simple functions without recursion - Uses time.Sleep(1ms) for reliable timing - Renamed to TestMultipleFunctionsTrackIndependently This resolves the duplicate effort and adopts the already-merged solution.
|
These changes were released in v1.195.0-test.0. |
what
TestMultipleRecursiveFunctionsIndependenttest inpkg/perf/perf_test.goTestMultipleFunctionsTrackIndependentlyto match its actual purposewhy
func1: expected non-zero duration, got 0sTestRecursiveFunctionTracking,TestRecursiveFunctionWrongPattern)changes
TestMultipleRecursiveFunctionsIndependenttoTestMultipleFunctionsTrackIndependentlycount=1(independent tracking)references
🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
Refactor