Skip to content

Conversation

@martincostello
Copy link
Member

Changes

Refactor two different test classes to try and avoid flakiness in CI.

Also fixes the IDE suggestions from Visual Studio while I was touching the files.

First:

[xUnit.net 00:00:04.36]     OpenTelemetry.Metrics.Tests.MetricExemplarTests.TestExemplarsExponentialHistogram(temporality: Cumulative) [FAIL]
[xUnit.net 00:00:04.36]       Assert.NotEqual() Failure: Values are equal
[xUnit.net 00:00:04.36]       Expected: Not 00000000000000000000000000000000
[xUnit.net 00:00:04.36]       Actual:       00000000000000000000000000000000
[xUnit.net 00:00:04.36]       Stack Trace:
[xUnit.net 00:00:04.36]         /home/runner/work/opentelemetry-dotnet/opentelemetry-dotnet/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs(844,0): at OpenTelemetry.Metrics.Tests.MetricExemplarTests.ValidateExemplars(IReadOnlyList`1 exemplars, DateTimeOffset startTime, DateTimeOffset endTime, IEnumerable`1 measurementValues, Func`2 getExemplarValueFunc)
[xUnit.net 00:00:04.36]         /home/runner/work/opentelemetry-dotnet/opentelemetry-dotnet/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs(670,0): at OpenTelemetry.Metrics.Tests.MetricExemplarTests.<TestExemplarsExponentialHistogram>g__ValidateSecondPhase|6_2(String instrumentName, MetricReaderTemporalityPreference temporality, DateTime testStartTime, List`1 exportedItems, ValueTuple`2[] firstMeasurementValues, ValueTuple`2[] secondMeasurementValues)
[xUnit.net 00:00:04.36]         /home/runner/work/opentelemetry-dotnet/opentelemetry-dotnet/test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs(624,0): at OpenTelemetry.Metrics.Tests.MetricExemplarTests.TestExemplarsExponentialHistogram(MetricReaderTemporalityPreference temporality)
[xUnit.net 00:00:04.36]            at InvokeStub_MetricExemplarTests.TestExemplarsExponentialHistogram(Object, Span`1)
[xUnit.net 00:00:04.36]            at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Second:

[xUnit.net 00:00:02.95]     OpenTelemetry.Metrics.Tests.MetricPointReclaimTests.MeasurementsAreAggregatedEvenAfterTheyAreDropped(emitMetricWithNoDimension: True) [FAIL]
[xUnit.net 00:00:02.95]       Assert.Equal() Failure: Values differ
[xUnit.net 00:00:02.95]       Expected: 3680
[xUnit.net 00:00:02.95]       Actual:   3670
[xUnit.net 00:00:02.96]       Stack Trace:
[xUnit.net 00:00:02.96]         Metrics\MetricPointReclaimTests.cs(174,0): at OpenTelemetry.Metrics.Tests.MetricPointReclaimTests.MeasurementsAreAggregatedEvenAfterTheyAreDropped(Boolean emitMetricWithNoDimension)

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)

Refactor two different test classes to try and avoid flakiness in CI.
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Nov 27, 2025
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6734   +/-   ##
=======================================
  Coverage   86.85%   86.85%           
=======================================
  Files         258      258           
  Lines       11990    11990           
=======================================
  Hits        10414    10414           
  Misses       1576     1576           
Flag Coverage Δ
unittests-Project-Experimental 86.67% <ø> (-0.03%) ⬇️
unittests-Project-Stable 86.46% <ø> (-0.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@martincostello martincostello marked this pull request as ready for review November 27, 2025 09:32
@martincostello martincostello requested a review from a team as a code owner November 27, 2025 09:32
Copilot AI review requested due to automatic review settings November 27, 2025 09:32
Copilot finished reviewing on behalf of martincostello November 27, 2025 09:33
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 addresses flaky test failures in two test classes by improving timing reliability and refactoring code for better clarity. The changes focus on ensuring proper resource cleanup timing and verifying that ForceFlush operations complete successfully.

  • Increased timeout for flush operations from 10 seconds to 15 seconds to accommodate slower CI environments
  • Wrapped MeterProvider instances in using blocks to ensure disposal happens after final assertions
  • Added assertions to verify ForceFlush operations succeed rather than silently ignoring failures

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
MetricPointReclaimTests.cs Refactored to ensure MeterProvider disposal occurs after all measurements are validated, converted variables to constants
MetricExemplarTests.cs Increased flush timeout and added assertions to verify ForceFlush success, simplified conditional expressions and loop variable destructuring

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Kielek Kielek added this pull request to the merge queue Nov 28, 2025
Merged via the queue into open-telemetry:main with commit 4e2c575 Nov 28, 2025
59 checks passed
@martincostello martincostello deleted the fix-flaky-tests branch November 28, 2025 07:55
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