diff --git a/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs b/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs index 7de367bf34d..8b96cb873c2 100644 --- a/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs +++ b/test/Polly.Extensions.Tests/Telemetry/ResilienceTelemetryDiagnosticSourceTests.cs @@ -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() { diff --git a/test/Polly.Extensions.Tests/Utils/ResilienceContextExtensionsTests.cs b/test/Polly.Extensions.Tests/Utils/ResilienceContextExtensionsTests.cs new file mode 100644 index 00000000000..e6209416c64 --- /dev/null +++ b/test/Polly.Extensions.Tests/Utils/ResilienceContextExtensionsTests.cs @@ -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)context.ResilienceEvents).Add(new ResilienceEvent(severity, "dummy")); + } +} diff --git a/test/Polly.TestUtils/TestUtilities.cs b/test/Polly.TestUtils/TestUtilities.cs index 0fd8e40a275..48db532993b 100644 --- a/test/Polly.TestUtils/TestUtilities.cs +++ b/test/Polly.TestUtils/TestUtilities.cs @@ -112,6 +112,12 @@ public static ResilienceContext WithResultType(this ResilienceContext context return context; } + public static ResilienceContext WithVoidResultType(this ResilienceContext context) + { + context.Initialize(true); + return context; + } + private sealed class CallbackDiagnosticSource : DiagnosticSource { private readonly Action _callback;