Skip to content

Commit

Permalink
PR comments and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Jan 3, 2024
1 parent 26301a6 commit 372cecb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,12 @@ private bool PermitHalfOpenCircuitTest_NeedsLock()
private void SetLastHandledOutcome_NeedsLock(Outcome<T> outcome)
{
_lastOutcome = outcome;

if (outcome.Exception is Exception exception)
{
_breakingException = exception;
}
_breakingException = outcome.Exception;
}

private BrokenCircuitException CreateBrokenCircuitException() => _breakingException switch
{
Exception exception => new BrokenCircuitException(exception.Message, exception),
Exception exception => new BrokenCircuitException(BrokenCircuitException.DefaultMessage, exception),
_ => new BrokenCircuitException(BrokenCircuitException.DefaultMessage)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,38 @@ public async Task OnActionPreExecute_CircuitOpenedByValue()
GetBlockedTill(controller).Should().Be(_timeProvider.GetUtcNow() + _options.BreakDuration);
}

[Fact]
public async Task OnActionPreExecute_CircuitOpened_EnsureExceptionStackTraceDoesNotGrow()
[InlineData(true)]
[InlineData(false)]
[Theory]
public async Task OnActionPreExecute_CircuitOpened_EnsureExceptionStackTraceDoesNotGrow(bool innerException)
{
var stacks = new List<string>();
var ctxt = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get();
using var controller = CreateController();

await OpenCircuit(controller, Outcome.FromResult(99));
await OpenCircuit(
controller,
innerException ? Outcome.FromException<int>(new InvalidOperationException()) : Outcome.FromResult(99));

for (int i = 0; i < 100; i++)
{
try
{
(await controller.OnActionPreExecuteAsync(ctxt)).Value.ThrowIfException();
(await controller.OnActionPreExecuteAsync(context)).Value.ThrowIfException();
}
catch (BrokenCircuitException e)
{
stacks.Add(e.StackTrace!);
e.Message.Should().Be("The circuit is now open and is not allowing calls.");

if (innerException)
{
e.InnerException.Should().BeOfType<InvalidOperationException>();
}
else
{
e.InnerException.Should().BeNull();
}
}
}

Expand Down

0 comments on commit 372cecb

Please sign in to comment.