File tree Expand file tree Collapse file tree 2 files changed +21
-11
lines changed
src/Polly.Core/CircuitBreaker/Controller
test/Polly.Core.Tests/CircuitBreaker/Controller Expand file tree Collapse file tree 2 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -302,16 +302,12 @@ private bool PermitHalfOpenCircuitTest_NeedsLock()
302302 private void SetLastHandledOutcome_NeedsLock ( Outcome < T > outcome )
303303 {
304304 _lastOutcome = outcome ;
305-
306- if ( outcome . Exception is Exception exception )
307- {
308- _breakingException = exception ;
309- }
305+ _breakingException = outcome . Exception ;
310306 }
311307
312308 private BrokenCircuitException CreateBrokenCircuitException ( ) => _breakingException switch
313309 {
314- Exception exception => new BrokenCircuitException ( exception . Message , exception ) ,
310+ Exception exception => new BrokenCircuitException ( BrokenCircuitException . DefaultMessage , exception ) ,
315311 _ => new BrokenCircuitException ( BrokenCircuitException . DefaultMessage )
316312 } ;
317313
Original file line number Diff line number Diff line change @@ -124,24 +124,38 @@ public async Task OnActionPreExecute_CircuitOpenedByValue()
124124 GetBlockedTill ( controller ) . Should ( ) . Be ( _timeProvider . GetUtcNow ( ) + _options . BreakDuration ) ;
125125 }
126126
127- [ Fact ]
128- public async Task OnActionPreExecute_CircuitOpened_EnsureExceptionStackTraceDoesNotGrow ( )
127+ [ InlineData ( true ) ]
128+ [ InlineData ( false ) ]
129+ [ Theory ]
130+ public async Task OnActionPreExecute_CircuitOpened_EnsureExceptionStackTraceDoesNotGrow ( bool innerException )
129131 {
130132 var stacks = new List < string > ( ) ;
131- var ctxt = ResilienceContextPool . Shared . Get ( ) ;
133+ var context = ResilienceContextPool . Shared . Get ( ) ;
132134 using var controller = CreateController ( ) ;
133135
134- await OpenCircuit ( controller , Outcome . FromResult ( 99 ) ) ;
136+ await OpenCircuit (
137+ controller ,
138+ innerException ? Outcome . FromException < int > ( new InvalidOperationException ( ) ) : Outcome . FromResult ( 99 ) ) ;
135139
136140 for ( int i = 0 ; i < 100 ; i ++ )
137141 {
138142 try
139143 {
140- ( await controller . OnActionPreExecuteAsync ( ctxt ) ) . Value . ThrowIfException ( ) ;
144+ ( await controller . OnActionPreExecuteAsync ( context ) ) . Value . ThrowIfException ( ) ;
141145 }
142146 catch ( BrokenCircuitException e )
143147 {
144148 stacks . Add ( e . StackTrace ! ) ;
149+ e . Message . Should ( ) . Be ( "The circuit is now open and is not allowing calls." ) ;
150+
151+ if ( innerException )
152+ {
153+ e . InnerException . Should ( ) . BeOfType < InvalidOperationException > ( ) ;
154+ }
155+ else
156+ {
157+ e . InnerException . Should ( ) . BeNull ( ) ;
158+ }
145159 }
146160 }
147161
You can’t perform that action at this time.
0 commit comments