@@ -14,19 +14,10 @@ public class TelemetryListenerImplTests : IDisposable
14
14
private readonly ILoggerFactory _loggerFactory ;
15
15
private readonly List < MeteringEvent > _events = new ( ) ;
16
16
private Action < TelemetryEventArguments < object , object > > ? _onEvent ;
17
- private IDisposable _metering ;
18
17
19
- public TelemetryListenerImplTests ( )
20
- {
21
- _metering = TestUtilities . EnablePollyMetering ( _events ) ;
22
- _loggerFactory = TestUtilities . CreateLoggerFactory ( out _logger ) ;
23
- }
18
+ public TelemetryListenerImplTests ( ) => _loggerFactory = TestUtilities . CreateLoggerFactory ( out _logger ) ;
24
19
25
- public void Dispose ( )
26
- {
27
- _metering . Dispose ( ) ;
28
- _loggerFactory . Dispose ( ) ;
29
- }
20
+ public void Dispose ( ) => _loggerFactory . Dispose ( ) ;
30
21
31
22
[ Fact ]
32
23
public void Meter_Ok ( )
@@ -113,6 +104,8 @@ public void WriteEvent_LoggingWithoutInstanceName_Ok()
113
104
[ Theory ]
114
105
public void WriteEvent_EnsureSeverityRespected ( ResilienceEventSeverity severity , LogLevel logLevel )
115
106
{
107
+ using var metering = TestUtilities . EnablePollyMetering ( _events ) ;
108
+
116
109
var telemetry = Create ( ) ;
117
110
ReportEvent ( telemetry , null , severity : severity ) ;
118
111
@@ -184,6 +177,7 @@ public void WriteExecutionAttempt_NotEnabled_EnsureNotLogged()
184
177
[ Theory ]
185
178
public void WriteEvent_MeteringWithoutEnrichers_Ok ( bool noOutcome , bool exception )
186
179
{
180
+ using var metering = TestUtilities . EnablePollyMetering ( _events ) ;
187
181
var telemetry = Create ( ) ;
188
182
Outcome < object > ? outcome = noOutcome switch
189
183
{
@@ -231,6 +225,7 @@ public void WriteEvent_MeteringWithoutEnrichers_Ok(bool noOutcome, bool exceptio
231
225
[ Theory ]
232
226
public void WriteExecutionAttemptEvent_Metering_Ok ( bool noOutcome , bool exception )
233
227
{
228
+ using var metering = TestUtilities . EnablePollyMetering ( _events ) ;
234
229
var telemetry = Create ( ) ;
235
230
var attemptArg = new ExecutionAttemptArguments ( 5 , TimeSpan . FromSeconds ( 50 ) , true ) ;
236
231
Outcome < object > ? outcome = noOutcome switch
@@ -279,8 +274,7 @@ public void WriteExecutionAttemptEvent_Metering_Ok(bool noOutcome, bool exceptio
279
274
[ Fact ]
280
275
public void WriteExecutionAttemptEvent_ShouldBeSkipped ( )
281
276
{
282
- _metering . Dispose ( ) ;
283
- _metering = TestUtilities . EnablePollyMetering ( _events , _ => false ) ;
277
+ using var metering = TestUtilities . EnablePollyMetering ( _events , _ => false ) ;
284
278
285
279
var telemetry = Create ( ) ;
286
280
var attemptArg = new ExecutionAttemptArguments ( 5 , TimeSpan . FromSeconds ( 50 ) , true ) ;
@@ -295,6 +289,8 @@ public void WriteExecutionAttemptEvent_ShouldBeSkipped()
295
289
[ Theory ]
296
290
public void WriteEvent_MeteringWithEnrichers_Ok ( int count )
297
291
{
292
+ using var metering = TestUtilities . EnablePollyMetering ( _events ) ;
293
+
298
294
const int DefaultDimensions = 7 ;
299
295
300
296
var telemetry = Create ( new [ ]
@@ -329,6 +325,7 @@ public void WriteEvent_MeteringWithEnrichers_Ok(int count)
329
325
[ Fact ]
330
326
public void WriteEvent_MeteringWithoutBuilderInstance_Ok ( )
331
327
{
328
+ using var metering = TestUtilities . EnablePollyMetering ( _events ) ;
332
329
var telemetry = Create ( ) ;
333
330
ReportEvent ( telemetry , null , instanceName : null ) ;
334
331
var events = GetEvents ( "resilience-events" ) [ 0 ] . Should ( ) . NotContainKey ( "pipeline-instance" ) ;
@@ -413,6 +410,8 @@ public void PipelineExecution_NoOutcome_Logged()
413
410
[ Theory ]
414
411
public void PipelineExecution_Metered ( bool healthy , bool exception )
415
412
{
413
+ using var metering = TestUtilities . EnablePollyMetering ( _events ) ;
414
+
416
415
var healthString = healthy ? "Healthy" : "Unhealthy" ;
417
416
var context = ResilienceContextPool . Shared . Get ( "op-key" ) . WithResultType < int > ( ) ;
418
417
var outcome = exception ? Outcome . FromException < object > ( new InvalidOperationException ( "dummy message" ) ) : Outcome . FromResult ( ( object ) 10 ) ;
@@ -472,8 +471,7 @@ public void PipelineExecution_Metered(bool healthy, bool exception)
472
471
[ Fact ]
473
472
public void PipelineExecuted_ShouldBeSkipped ( )
474
473
{
475
- _metering . Dispose ( ) ;
476
- _metering = TestUtilities . EnablePollyMetering ( _events , _ => false ) ;
474
+ using var metering = TestUtilities . EnablePollyMetering ( _events , _ => false ) ;
477
475
478
476
var telemetry = Create ( ) ;
479
477
var attemptArg = new PipelineExecutedArguments ( TimeSpan . FromSeconds ( 50 ) ) ;
0 commit comments