Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
better test asserts
  • Loading branch information
cijothomas committed Nov 29, 2023
commit d3ba4d4e51d52b23b66813dbaecda26892105d65
21 changes: 14 additions & 7 deletions test/OpenTelemetry.Tests/Metrics/MetricApiTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ public void MetricInstrumentationScopeIsExportedCorrectly()
Assert.Equal(meterName, metric.MeterName);
Assert.Equal(meterVersion, metric.MeterVersion);

bool containsMeterTags = metric.MeterTags.Any(kvp =>
kvp.Key == meterTags[0].Key && Equals(kvp.Value, meterTags[0].Value));
Assert.True(containsMeterTags);
Assert.Single(metric.MeterTags.Attributes.Where(kvp => kvp.Key == meterTags[0].Key && kvp.Value == meterTags[0].Value));
}

[Fact]
Expand Down Expand Up @@ -238,7 +236,7 @@ public void MetricInstrumentationScopeAttributesAreNotTreatedAsIdentifyingProper
var counter1 = meter1.CreateCounter<long>("my-counter");
counter1.Add(10);
var counter2 = meter2.CreateCounter<long>("my-counter");
counter2.Add(10);
counter2.Add(15);
meterProvider.ForceFlush(MaxTimeToAllowForFlush);

// The instruments differ only in the Meter.Tags, which is not an identifying property.
Expand All @@ -250,9 +248,18 @@ public void MetricInstrumentationScopeAttributesAreNotTreatedAsIdentifyingProper
Assert.Equal(meterName, metric.MeterName);
Assert.Equal(meterVersion, metric.MeterVersion);

bool containsMeterTags = metric.MeterTags.Any(kvp =>
kvp.Key == meterTags1[0].Key && Equals(kvp.Value, meterTags1[0].Value));
Assert.True(containsMeterTags);
Assert.Single(metric.MeterTags.Attributes.Where(kvp => kvp.Key == meterTags1[0].Key && kvp.Value == meterTags1[0].Value));
Assert.DoesNotContain(metric.MeterTags.Attributes.Where(kvp => kvp.Key == meterTags2[0].Key && kvp.Value == meterTags2[0].Value));

List<MetricPoint> metricPoints = new List<MetricPoint>();
foreach (ref readonly var mp in metric.GetMetricPoints())
{
metricPoints.Add(mp);
}

Assert.Single(metricPoints);
var metricPoint1 = metricPoints[0];
Assert.Equal(25, metricPoint1.GetSumLong());
}

[Fact]
Expand Down