Skip to content

Commit

Permalink
kill mutants
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Aug 11, 2023
1 parent 3cb5b0f commit f87ddce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,18 @@ public void PipelineExecution_Logged(bool healthy, bool exception)
messages[0].LogLevel.Should().Be(healthy ? LogLevel.Debug : LogLevel.Warning);
}

[Fact]
public void PipelineExecution_VoidResult_Ok()
{
var context = ResilienceContextPool.Shared.Get("op-key").WithVoidResultType();
var telemetry = Create();
ReportEvent(telemetry, outcome: null, arg: new PipelineExecutingArguments(), context: context);

var messages = _logger.GetRecords(new EventId(1, "StrategyExecuting")).ToList();
messages.Should().HaveCount(1);
messages[0].Message.Should().Be("Resilience strategy executing. Source: 'my-builder/builder-instance', Operation Key: 'op-key', Result Type: 'void'");
}

[Fact]
public void PipelineExecution_NoOutcome_Logged()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Polly.Telemetry;

namespace Polly.Extensions.Tests.Utils;

public class ResilienceContextExtensionsTests
{
[Fact]
public void IsHealthy_Ok()
{
var context = ResilienceContextPool.Shared.Get();
AddEvent(context, ResilienceEventSeverity.Warning);
context.IsExecutionHealthy().Should().BeFalse();

context = ResilienceContextPool.Shared.Get();
context.IsExecutionHealthy().Should().BeTrue();

context = ResilienceContextPool.Shared.Get();
AddEvent(context, ResilienceEventSeverity.Information);
context.IsExecutionHealthy().Should().BeTrue();

context = ResilienceContextPool.Shared.Get();
AddEvent(context, ResilienceEventSeverity.Information);
AddEvent(context, ResilienceEventSeverity.Warning);
context.IsExecutionHealthy().Should().BeFalse();
}

private static void AddEvent(ResilienceContext context, ResilienceEventSeverity severity)
{
((List<ResilienceEvent>)context.ResilienceEvents).Add(new ResilienceEvent(severity, "dummy"));
}
}
6 changes: 6 additions & 0 deletions test/Polly.TestUtils/TestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public static ResilienceContext WithResultType<T>(this ResilienceContext context
return context;
}

public static ResilienceContext WithVoidResultType(this ResilienceContext context)
{
context.Initialize<VoidResult>(true);
return context;
}

private sealed class CallbackDiagnosticSource : DiagnosticSource
{
private readonly Action<TelemetryEventArguments> _callback;
Expand Down

0 comments on commit f87ddce

Please sign in to comment.