Minor improvement to duplicate instrument test (#2833)

This commit is contained in:
Cijo Thomas 2022-01-29 17:20:11 -08:00 committed by GitHub
parent 874285194b
commit b6d45ccb46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 10 deletions

View File

@ -171,21 +171,28 @@ namespace OpenTelemetry.Metrics.Tests
using var meterProvider = meterProviderBuilder.Build(); using var meterProvider = meterProviderBuilder.Build();
// Expecting one metric stream.
var counterLong = meter.CreateCounter<long>("name1"); var counterLong = meter.CreateCounter<long>("name1");
var anotherCounterSameName = meter.CreateCounter<long>("name1");
counterLong.Add(10); counterLong.Add(10);
anotherCounterSameName.Add(20);
counterLong.Add(10);
anotherCounterSameName.Add(20);
meterProvider.ForceFlush(MaxTimeToAllowForFlush); meterProvider.ForceFlush(MaxTimeToAllowForFlush);
Assert.Single(exportedItems); Assert.Single(exportedItems);
// The following will be ignored as var metric = exportedItems[0];
// metric of same name exists. Assert.Equal("name1", metric.Name);
// Metric stream will remain one. List<MetricPoint> metricPoints = new List<MetricPoint>();
var anotherCounterSameName = meter.CreateCounter<long>("name1"); foreach (ref readonly var mp in metric.GetMetricPoints())
anotherCounterSameName.Add(10); {
counterLong.Add(10); metricPoints.Add(mp);
exportedItems.Clear(); }
meterProvider.ForceFlush(MaxTimeToAllowForFlush);
Assert.Single(exportedItems); Assert.Single(metricPoints);
var metricPoint1 = metricPoints[0];
Assert.Equal(20, metricPoint1.GetSumLong());
} }
[Theory] [Theory]