Skip to content

Commit

Permalink
[Exporter,Prometheus] Fix PrometheusCollectionManagerTests (#3714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Sep 30, 2022
1 parent 31eb92c commit 9809cf6
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
{
public sealed class PrometheusCollectionManagerTests
{
#if PROMETHEUS_HTTP_LISTENER
[Fact(Skip = "Might be flaky. Might be a bug. See: https://github.com/open-telemetry/opentelemetry-dotnet/issues/3679")]
#else
[Fact]
[Theory]
[InlineData(0)] // disable cache, default value for HttpListener
#if PROMETHEUS_ASPNETCORE
[InlineData(300)] // default value for AspNetCore, no possibility to set on HttpListener
#endif
public async Task EnterExitCollectTest()
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()
#elif PROMETHEUS_ASPNETCORE
.AddPrometheusExporter()
.AddPrometheusExporter(x => x.ScrapeResponseCacheDurationMilliseconds = scrapeResponseCacheDurationMilliseconds)
#endif
.Build())
{
Expand Down Expand Up @@ -108,9 +109,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
{
Expand Down Expand Up @@ -143,7 +153,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);

Expand Down

0 comments on commit 9809cf6

Please sign in to comment.