From 162650b1efbcf7bb91181278cf2b8b90ba2e81f8 Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Thu, 14 Apr 2022 17:54:47 -0700 Subject: [PATCH] Test when periodic metric reader options is null --- .../OtlpMetricsExporterTests.cs | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs index 50f3ce04bf0..3d55826ae08 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs @@ -47,21 +47,39 @@ public void TestAddOtlpExporter_SetsCorrectMetricReaderDefaults() .AddOtlpExporter() .Build(); - var bindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance; + CheckMetricReaderDefaults(); - var metricReader = typeof(MetricReader) - .Assembly - .GetType("OpenTelemetry.Metrics.MeterProviderSdk") - .GetField("reader", bindingFlags) - .GetValue(meterProvider) as PeriodicExportingMetricReader; + meterProvider.Dispose(); - Assert.NotNull(metricReader); + meterProvider = Sdk.CreateMeterProviderBuilder() + .AddOtlpExporter((exporterOptions, metricReaderOptions) => + { + metricReaderOptions.PeriodicExportingMetricReaderOptions = null; + }) + .Build(); + + CheckMetricReaderDefaults(); + + meterProvider.Dispose(); - var exportIntervalMilliseconds = (int)typeof(PeriodicExportingMetricReader) - .GetField("ExportIntervalMilliseconds", bindingFlags) - .GetValue(metricReader); + void CheckMetricReaderDefaults() + { + var bindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance; + + var metricReader = typeof(MetricReader) + .Assembly + .GetType("OpenTelemetry.Metrics.MeterProviderSdk") + .GetField("reader", bindingFlags) + .GetValue(meterProvider) as PeriodicExportingMetricReader; + + Assert.NotNull(metricReader); - Assert.Equal(60000, exportIntervalMilliseconds); + var exportIntervalMilliseconds = (int)typeof(PeriodicExportingMetricReader) + .GetField("ExportIntervalMilliseconds", bindingFlags) + .GetValue(metricReader); + + Assert.Equal(60000, exportIntervalMilliseconds); + } } [Fact]