Skip to content

Fix flaky TestMultipleRecursiveFunctionsIndependent test - #1626

Merged
Andriy Knysh (aknysh) merged 5 commits into
mainfrom
fix-flaky-perf-test
Oct 14, 2025
Merged

Andriy Knysh (aknysh) merged 5 commits into
mainfrom
fix-flaky-perf-test

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Oct 14, 2025 •

Copy link
Copy Markdown
Member

what

  • Fix flaky TestMultipleRecursiveFunctionsIndependent test in pkg/perf/perf_test.go
  • Simplify test by removing unnecessary recursion complexity
  • Rename test to TestMultipleFunctionsTrackIndependently to match its actual purpose

why

  • The test was failing intermittently on Windows with: func1: expected non-zero duration, got 0s
  • The test name suggested it was about recursive functions, but recursion added complexity without testing value
  • Other tests already cover recursive tracking behavior (TestRecursiveFunctionTracking, TestRecursiveFunctionWrongPattern)
  • The actual purpose is to verify that multiple functions track independently without interfering with each other's metrics

changes

  • Removed all recursion logic - simplified to two basic functions
  • Renamed test from TestMultipleRecursiveFunctionsIndependent to TestMultipleFunctionsTrackIndependently
  • Each function sleeps 1ms to ensure measurable duration on all platforms
  • Test verifies core behavior:
    • Each function has count=1 (independent tracking)
    • Both functions tracked separately in registry (2 entries)
    • Both functions have non-zero duration (duration tracking works)
  • Removed flaky timing comparisons that caused intermittent failures

references

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Renamed a test to better reflect independent tracking behavior.
    • Simplified the scenario from recursive calls to straightforward function calls.
    • Updated assertions to verify two distinct entries with non-zero durations and single-call counts.
    • Improved error messages and comments for clarity.
  • Refactor

    • Streamlined test flow by removing recursion and using simpler work units, improving readability and maintainability without changing user-facing functionality.

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]>
@github-actions github-actions Bot added the size/s Small size PR label Oct 14, 2025
@osterman Erik Osterman (Cloud Posse) (osterman) added the no-release Do not create a new release (wait for additional code changes) label Oct 14, 2025
@osterman

Copy link
Copy Markdown
Member Author

CodeRabbit (@coderabbitai) full review

@coderabbitai

coderabbitai Bot commented Oct 14, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented Oct 14, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Renamed and refactored a perf test: TestMultipleRecursiveFunctionsIndependent → TestMultipleFunctionsTrackIndependently. Replaced recursive work with two simple non-recursive functions, invoked once each, and updated assertions to verify two registry entries, each with count==1 and Total > 0.

Changes

Cohort / File(s) Summary
Perf test refactor
pkg/perf/perf_test.go
Renamed test to TestMultipleFunctionsTrackIndependently. Replaced recursive function implementations with two simple non-recursive functions (single top-level call each). Updated test flow to call func1() and func2() directly. Adjusted assertions to expect exactly two registry entries and that each metric has Count == 1 and Total > 0; removed recursive-depth-based ordering checks. Updated comments and error messages to reflect independence of metrics.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

patch

Suggested reviewers

  • aknysh

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly states that the pull request addresses a flaky test named TestMultipleRecursiveFunctionsIndependent, accurately reflecting the main objective to simplify and stabilize that test without extraneous detail.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-flaky-perf-test

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6934f74 and ff2b465.

📒 Files selected for processing (1)
  • pkg/perf/perf_test.go (3 hunks)
⏰ 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)
  • GitHub Check: Summary
🔇 Additional comments (4)
pkg/perf/perf_test.go (4)

852-865: Good rename and clearer test purpose.

The function name now accurately reflects what's being tested—independent tracking without recursion. The updated comments make the intent crystal clear.


867-881: Smart simplification to fix flakiness.

Replacing recursion with simple 1ms sleeps ensures measurable duration across platforms while keeping the test focused on independent tracking. This directly addresses the Windows timing issues mentioned in the PR.


883-885: Clean, direct function calls.

Simple invocation pattern matches the test's purpose perfectly.


902-914: Excellent assertion improvements.

The explicit registry size check and non-zero duration validations make the test more robust and failures more actionable. These directly address the flaky behavior that motivated this refactor.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 14, 2025
@codecov

codecov Bot commented Oct 14, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.53%. Comparing base (348a7a0) to head (9d67117).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 64.53% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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]>
@osterman

Copy link
Copy Markdown
Member Author

CodeRabbit (@coderabbitai) review

@coderabbitai

coderabbitai Bot commented Oct 14, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aknysh
Andriy Knysh (aknysh) merged commit befa8d8 into main Oct 14, 2025
@aknysh
Andriy Knysh (aknysh) deleted the fix-flaky-perf-test branch October 14, 2025 19:21
Erik Osterman (Cloud Posse) (osterman) added a commit that referenced this pull request Oct 14, 2025
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.
@github-actions

Copy link
Copy Markdown

These changes were released in v1.195.0-test.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-release Do not create a new release (wait for additional code changes) size/s Small size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants