From dfb684ec9b62c1ef067ea8ee1a5f506841160c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 23 Sep 2022 21:04:24 +0200 Subject: [PATCH] Disabled cache test --- .../PrometheusCollectionManagerTests.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs index 70780738a06..7a9aaa34961 100644 --- a/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs +++ b/test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs @@ -29,17 +29,20 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests { public sealed class PrometheusCollectionManagerTests { - [Fact] - public async Task EnterExitCollectTest() + [Theory] + [InlineData(0)] // disable cache + [InlineData(300)] // default value + public async Task EnterExitCollectTest(int scrapeResponseCacheDurationMilliseconds) { + bool cacheEnabled = scrapeResponseCacheDurationMilliseconds != 0; using var meter = new Meter(Utils.GetCurrentMethodName()); using (var provider = Sdk.CreateMeterProviderBuilder() .AddMeter(meter.Name) #if PROMETHEUS_HTTP_LISTENER - .AddPrometheusHttpListener() + .AddPrometheusHttpListener(x => x.ScrapeResponseCacheDurationMilliseconds = scrapeResponseCacheDurationMilliseconds) #elif PROMETHEUS_ASPNETCORE - .AddPrometheusExporter() + .AddPrometheusExporter(x => x.ScrapeResponseCacheDurationMilliseconds = scrapeResponseCacheDurationMilliseconds) #endif .Build()) { @@ -104,9 +107,18 @@ public async Task EnterExitCollectTest() var response = await task.ConfigureAwait(false); try { - Assert.Equal(1, runningCollectCount); - Assert.True(response.FromCache); - Assert.Equal(firstResponse.CollectionResponse.GeneratedAtUtc, response.GeneratedAtUtc); + if (cacheEnabled) + { + Assert.Equal(1, runningCollectCount); + Assert.True(response.FromCache); + Assert.Equal(firstResponse.CollectionResponse.GeneratedAtUtc, response.GeneratedAtUtc); + } + else + { + Assert.Equal(2, runningCollectCount); + Assert.False(response.FromCache); + Assert.True(firstResponse.CollectionResponse.GeneratedAtUtc < response.GeneratedAtUtc); + } } finally { @@ -139,7 +151,7 @@ public async Task EnterExitCollectTest() await Task.WhenAll(collectTasks).ConfigureAwait(false); - Assert.Equal(2, runningCollectCount); + Assert.Equal(cacheEnabled ? 2 : 3, runningCollectCount); Assert.NotEqual(firstResponse.ViewPayload, collectTasks[0].Result.ViewPayload); Assert.NotEqual(firstResponse.CollectionResponse.GeneratedAtUtc, collectTasks[0].Result.CollectionResponse.GeneratedAtUtc);