From a44ba44278d266fe5df4e4f90873c5bea43986f0 Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Tue, 20 Jun 2023 11:07:49 +0200 Subject: [PATCH] code coverage fixes --- .../Controller/CircuitStateController.cs | 12 +++--------- src/Polly.Core/OutcomeArguments.cs | 2 -- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs b/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs index 184014c04df..cbb46ca06d8 100644 --- a/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs +++ b/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs @@ -19,7 +19,7 @@ internal sealed class CircuitStateController : IDisposable private DateTimeOffset _blockedUntil; private CircuitState _circuitState = CircuitState.Closed; private Outcome? _lastOutcome; - private BrokenCircuitException? _breakingException; + private BrokenCircuitException _breakingException = new(); private bool _disposed; public CircuitStateController( @@ -134,8 +134,8 @@ public ValueTask CloseCircuitAsync(ResilienceContext context) exception = _circuitState switch { - CircuitState.Open => GetBreakingException_NeedsLock(), - CircuitState.HalfOpen when isHalfOpen is false => GetBreakingException_NeedsLock(), + CircuitState.Open => _breakingException, + CircuitState.HalfOpen when isHalfOpen is false => _breakingException, CircuitState.Isolated => new IsolatedCircuitException(), _ => null }; @@ -261,7 +261,6 @@ private void CloseCircuit_NeedsLock(Outcome outcome, bool manual, ResilienceC _blockedUntil = DateTimeOffset.MinValue; _lastOutcome = null; - _breakingException = null; CircuitState priorState = _circuitState; _circuitState = CircuitState.Closed; @@ -294,7 +293,6 @@ private bool PermitHalfOpenCircuitTest_NeedsLock() private void SetLastHandledOutcome_NeedsLock(Outcome outcome) { _lastOutcome = outcome.AsOutcome(); - _breakingException = null; if (outcome.Exception is Exception exception) { @@ -304,12 +302,8 @@ private void SetLastHandledOutcome_NeedsLock(Outcome outcome) { _breakingException = new BrokenCircuitException(BrokenCircuitException.DefaultMessage, result!); } - - _breakingException?.TrySetStackTrace(); } - private BrokenCircuitException GetBreakingException_NeedsLock() => _breakingException ?? new BrokenCircuitException(); - private void OpenCircuit_NeedsLock(Outcome outcome, bool manual, ResilienceContext context, out Task? scheduledTask) { OpenCircuitFor_NeedsLock(outcome, _breakDuration, manual, context, out scheduledTask); diff --git a/src/Polly.Core/OutcomeArguments.cs b/src/Polly.Core/OutcomeArguments.cs index 9fa8b5a9ef6..89345357188 100644 --- a/src/Polly.Core/OutcomeArguments.cs +++ b/src/Polly.Core/OutcomeArguments.cs @@ -52,7 +52,5 @@ public OutcomeArguments(ResilienceContext context, Outcome outcome, TAr /// Gets the result, if any, produced by the resilience operation or event. /// public TResult? Result => Outcome.Result; - - internal OutcomeArguments AsObjectArguments() => new(Context, Outcome.AsOutcome(), Arguments); } }