Skip to content

Commit

Permalink
Disabled cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Sep 23, 2022
1 parent 2fcd36f commit dfb684e
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit dfb684e

Please sign in to comment.