diff --git a/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs b/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs index 3476430c35..f68d3121b0 100644 --- a/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs +++ b/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs @@ -41,7 +41,7 @@ public void EventCounter() options.AddEventSources(source.Name); }) .AddInMemoryExporter(metricItems) - .Build(); + .Build()!; // Act counter.WriteMetric(1997.0202); @@ -67,7 +67,7 @@ public void IncrementingEventCounter() options.AddEventSources(source.Name); }) .AddInMemoryExporter(metricItems) - .Build(); + .Build()!; // Act incCounter.Increment(1); @@ -96,7 +96,7 @@ public void PollingCounter() options.AddEventSources(source.Name); }) .AddInMemoryExporter(metricItems) - .Build(); + .Build()!; // Act var metric = AwaitExport(meterProvider, metricItems, expectedInstrumentName: "ec.c.poll-c"); @@ -122,7 +122,7 @@ public void IncrementingPollingCounter() options.AddEventSources(source.Name); }) .AddInMemoryExporter(metricItems) - .Build(); + .Build()!; // Act var metric = AwaitExport(meterProvider, metricItems, expectedInstrumentName: "ec.d.inc-poll-c"); @@ -133,13 +133,6 @@ public void IncrementingPollingCounter() Assert.Equal(1, GetActualValue(metric)); } - [Fact] - public void ThrowExceptionWhenBuilderIsNull() - { - MeterProviderBuilder builder = null; - Assert.Throws(() => builder.AddEventCountersInstrumentation()); - } - [Fact] public void ThrowExceptionForUnsupportedEventSources() { @@ -177,7 +170,7 @@ public void EventSourceNameShortening(string sourceName, string eventName, strin options.AddEventSources(source.Name); }) .AddInMemoryExporter(metricItems) - .Build(); + .Build()!; // Act connections.Increment(1); @@ -235,16 +228,16 @@ private static double GetActualValue(Metric metric) return sum; } - private static Metric AwaitExport(MeterProvider meterProvider, List exportedItems, string expectedInstrumentName) + private static Metric? AwaitExport(MeterProvider meterProvider, List exportedItems, string expectedInstrumentName) { - Metric metric = null; + Metric? metric = null; SpinWait.SpinUntil( () => { Thread.Sleep(100); meterProvider.ForceFlush(); - metric = exportedItems.Where(x => x.Name == expectedInstrumentName).FirstOrDefault(); + metric = exportedItems.FirstOrDefault(x => x.Name == expectedInstrumentName); return metric != null; }, 10_000); diff --git a/test/OpenTelemetry.Instrumentation.EventCounters.Tests/OpenTelemetry.Instrumentation.EventCounters.Tests.csproj b/test/OpenTelemetry.Instrumentation.EventCounters.Tests/OpenTelemetry.Instrumentation.EventCounters.Tests.csproj index c7a95c7e4a..81177f9a06 100644 --- a/test/OpenTelemetry.Instrumentation.EventCounters.Tests/OpenTelemetry.Instrumentation.EventCounters.Tests.csproj +++ b/test/OpenTelemetry.Instrumentation.EventCounters.Tests/OpenTelemetry.Instrumentation.EventCounters.Tests.csproj @@ -4,7 +4,6 @@ net7.0;net6.0 true - disable