Skip to content

Commit

Permalink
Add test that verifies overriding by using ConfigureTelemetry (#1787)
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk authored Nov 14, 2023
1 parent 6978c8f commit 2a81c43
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Polly.Registry;

namespace Polly.Extensions.Tests.Issues;

public partial class IssuesTests
{
[Fact]
public void OverrideLoggerFactory_ByExplicitConfigureTelemetryCall_1783()
{
// Arrange
using var loggerFactory1 = new FakeLoggerFactory();
using var loggerFactory2 = new FakeLoggerFactory();
var services = new ServiceCollection();
services.TryAddSingleton<ILoggerFactory>(loggerFactory1);

// Act
services.AddResiliencePipeline("dummy", builder =>
{
builder.AddTimeout(TimeSpan.FromSeconds(1));

// This call should override the base factory
builder.ConfigureTelemetry(loggerFactory2);
});

// Assert
var provider = services.BuildServiceProvider().GetRequiredService<ResiliencePipelineProvider<string>>();

provider.GetPipeline("dummy").Execute(() => { });

loggerFactory1.FakeLogger.GetRecords().Should().BeEmpty();
loggerFactory2.FakeLogger.GetRecords().Should().NotBeEmpty();
}
}

0 comments on commit 2a81c43

Please sign in to comment.