@@ -64,6 +64,7 @@ public void AddCircuitBreaker_Validation()
64
64
[ Fact ]
65
65
public void AddCircuitBreaker_IntegrationTest ( )
66
66
{
67
+ var cancellationToken = TestContext . Current . CancellationToken ;
67
68
int opened = 0 ;
68
69
int closed = 0 ;
69
70
int halfOpened = 0 ;
@@ -88,36 +89,36 @@ public void AddCircuitBreaker_IntegrationTest()
88
89
89
90
for ( int i = 0 ; i < 10 ; i ++ )
90
91
{
91
- strategy . Execute ( _ => - 1 ) ;
92
+ strategy . Execute ( _ => - 1 , cancellationToken ) ;
92
93
}
93
94
94
95
// Circuit opened
95
96
opened . Should ( ) . Be ( 1 ) ;
96
97
halfOpened . Should ( ) . Be ( 0 ) ;
97
98
closed . Should ( ) . Be ( 0 ) ;
98
- BrokenCircuitException exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 ) ) ;
99
+ BrokenCircuitException exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 , cancellationToken ) ) ;
99
100
exception . RetryAfter . Should ( ) . Be ( breakDuration ) ;
100
101
101
102
// Circuit still open after some time
102
103
timeProvider . Advance ( halfBreakDuration ) ;
103
104
opened . Should ( ) . Be ( 1 ) ;
104
105
halfOpened . Should ( ) . Be ( 0 ) ;
105
106
closed . Should ( ) . Be ( 0 ) ;
106
- exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 ) ) ;
107
+ exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 , cancellationToken ) ) ;
107
108
exception . RetryAfter . Should ( ) . Be ( halfBreakDuration ) ;
108
109
109
110
// Circuit Half Opened
110
111
timeProvider . Advance ( halfBreakDuration ) ;
111
- strategy . Execute ( _ => - 1 ) ;
112
- exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 ) ) ;
112
+ strategy . Execute ( _ => - 1 , cancellationToken ) ;
113
+ exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 , cancellationToken ) ) ;
113
114
opened . Should ( ) . Be ( 2 ) ;
114
115
halfOpened . Should ( ) . Be ( 1 ) ;
115
116
closed . Should ( ) . Be ( 0 ) ;
116
117
exception . RetryAfter . Should ( ) . Be ( breakDuration ) ;
117
118
118
119
// Now close it
119
120
timeProvider . Advance ( breakDuration ) ;
120
- strategy . Execute ( _ => 0 ) ;
121
+ strategy . Execute ( _ => 0 , cancellationToken ) ;
121
122
opened . Should ( ) . Be ( 2 ) ;
122
123
halfOpened . Should ( ) . Be ( 2 ) ;
123
124
closed . Should ( ) . Be ( 1 ) ;
@@ -126,6 +127,7 @@ public void AddCircuitBreaker_IntegrationTest()
126
127
[ Fact ]
127
128
public void AddCircuitBreaker_IntegrationTest_WithBreakDurationGenerator ( )
128
129
{
130
+ var cancellationToken = TestContext . Current . CancellationToken ;
129
131
int opened = 0 ;
130
132
int closed = 0 ;
131
133
int halfOpened = 0 ;
@@ -151,36 +153,36 @@ public void AddCircuitBreaker_IntegrationTest_WithBreakDurationGenerator()
151
153
152
154
for ( int i = 0 ; i < 10 ; i ++ )
153
155
{
154
- strategy . Execute ( _ => - 1 ) ;
156
+ strategy . Execute ( _ => - 1 , cancellationToken ) ;
155
157
}
156
158
157
159
// Circuit opened
158
160
opened . Should ( ) . Be ( 1 ) ;
159
161
halfOpened . Should ( ) . Be ( 0 ) ;
160
162
closed . Should ( ) . Be ( 0 ) ;
161
- BrokenCircuitException exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 ) ) ;
163
+ BrokenCircuitException exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 , cancellationToken ) ) ;
162
164
exception . RetryAfter . Should ( ) . Be ( breakDuration ) ;
163
165
164
166
// Circuit still open after some time
165
167
timeProvider . Advance ( halfBreakDuration ) ;
166
168
opened . Should ( ) . Be ( 1 ) ;
167
169
halfOpened . Should ( ) . Be ( 0 ) ;
168
170
closed . Should ( ) . Be ( 0 ) ;
169
- exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 ) ) ;
171
+ exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 , cancellationToken ) ) ;
170
172
exception . RetryAfter . Should ( ) . Be ( halfBreakDuration ) ;
171
173
172
174
// Circuit Half Opened
173
175
timeProvider . Advance ( halfBreakDuration ) ;
174
- strategy . Execute ( _ => - 1 ) ;
175
- exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 ) ) ;
176
+ strategy . Execute ( _ => - 1 , cancellationToken ) ;
177
+ exception = Assert . Throws < BrokenCircuitException > ( ( ) => strategy . Execute ( _ => 0 , cancellationToken ) ) ;
176
178
opened . Should ( ) . Be ( 2 ) ;
177
179
halfOpened . Should ( ) . Be ( 1 ) ;
178
180
closed . Should ( ) . Be ( 0 ) ;
179
181
exception . RetryAfter . Should ( ) . Be ( breakDuration ) ;
180
182
181
183
// Now close it
182
184
timeProvider . Advance ( breakDuration ) ;
183
- strategy . Execute ( _ => 0 ) ;
185
+ strategy . Execute ( _ => 0 , cancellationToken ) ;
184
186
opened . Should ( ) . Be ( 2 ) ;
185
187
halfOpened . Should ( ) . Be ( 2 ) ;
186
188
closed . Should ( ) . Be ( 1 ) ;
@@ -189,8 +191,9 @@ public void AddCircuitBreaker_IntegrationTest_WithBreakDurationGenerator()
189
191
[ Fact ]
190
192
public async Task AddCircuitBreakers_WithIsolatedManualControl_ShouldBeIsolated ( )
191
193
{
194
+ var cancellationToken = TestContext . Current . CancellationToken ;
192
195
var manualControl = new CircuitBreakerManualControl ( ) ;
193
- await manualControl . IsolateAsync ( ) ;
196
+ await manualControl . IsolateAsync ( cancellationToken ) ;
194
197
195
198
var strategy1 = new ResiliencePipelineBuilder ( )
196
199
. AddCircuitBreaker ( new ( ) { ManualControl = manualControl } )
@@ -203,7 +206,7 @@ public async Task AddCircuitBreakers_WithIsolatedManualControl_ShouldBeIsolated(
203
206
strategy1 . Invoking ( s => s . Execute ( ( ) => { } ) ) . Should ( ) . Throw < IsolatedCircuitException > ( ) . Where ( e => e . RetryAfter == null ) ;
204
207
strategy2 . Invoking ( s => s . Execute ( ( ) => { } ) ) . Should ( ) . Throw < IsolatedCircuitException > ( ) . Where ( e => e . RetryAfter == null ) ;
205
208
206
- await manualControl . CloseAsync ( ) ;
209
+ await manualControl . CloseAsync ( cancellationToken ) ;
207
210
208
211
strategy1 . Execute ( ( ) => { } ) ;
209
212
strategy2 . Execute ( ( ) => { } ) ;
0 commit comments