Skip to content

Conversation

@martincostello
Copy link
Member

Fix flaky test observed in #6621.

Changes

Refactor MetricPointReclaimTests tests to avoid possible race condition, extend assertions and improve the code.

Will run a few times in draft to check for lack of failures.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- Simplify `if` statement.
- Fix typo in variable name.
Assert that the metrics are flushed successfully.
- Assert more exports succeed.
- Simplify `while` loop.
- Remove redundant `!`.
- Use collection expression.
Use `Interlocked.Add()` to avoid potential races updating `Sum` if two exports overlap.
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Oct 20, 2025
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.82%. Comparing base (cb8d9e9) to head (b198f6d).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6622      +/-   ##
==========================================
+ Coverage   86.70%   86.82%   +0.11%     
==========================================
  Files         258      258              
  Lines       11955    11955              
==========================================
+ Hits        10366    10380      +14     
+ Misses       1589     1575      -14     
Flag Coverage Δ
unittests-Project-Experimental 86.78% <ø> (+0.11%) ⬆️
unittests-Project-Stable 86.76% <ø> (+0.10%) ⬆️

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

@martincostello martincostello marked this pull request as ready for review October 20, 2025 15:23
@martincostello martincostello requested a review from a team as a code owner October 20, 2025 15:23
Copilot AI review requested due to automatic review settings October 20, 2025 15:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors MetricPointReclaimTests to fix a flaky test by addressing potential race conditions and improving code quality. The changes focus on thread-safety improvements and code modernization.

Key Changes:

  • Added thread-safe sum accumulation using Interlocked.Add to prevent race conditions
  • Added assertions on ForceFlush() return values to verify export success
  • Modernized code syntax (collection expressions, simplified conditionals)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@martincostello
Copy link
Member Author

I'm not 100% sure these changes definitely fix the issue observed, but there's been no reoccurrence in 5 re-runs.

@Kielek Kielek changed the title [Infra] Fix flaky test [Infra/OpenTelemetry] Fix flaky test Oct 21, 2025
@Kielek Kielek merged commit 797ac1b into open-telemetry:main Oct 21, 2025
247 of 249 checks passed
@martincostello martincostello deleted the fix-flaky-test-2 branch October 21, 2025 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants