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 af8d45a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,37 @@ 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!);

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

Expand Down

0 comments on commit af8d45a

Please sign in to comment.