Skip to content

Commit d5971c5

Browse files
committed
Merge remote-tracking branch 'origin/main' into mtomka/improve-logs
2 parents 2f534a5 + 02687e8 commit d5971c5

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs

+13-15
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@ public class TelemetryListenerImplTests : IDisposable
1414
private readonly ILoggerFactory _loggerFactory;
1515
private readonly List<MeteringEvent> _events = new();
1616
private Action<TelemetryEventArguments<object, object>>? _onEvent;
17-
private IDisposable _metering;
1817

19-
public TelemetryListenerImplTests()
20-
{
21-
_metering = TestUtilities.EnablePollyMetering(_events);
22-
_loggerFactory = TestUtilities.CreateLoggerFactory(out _logger);
23-
}
18+
public TelemetryListenerImplTests() => _loggerFactory = TestUtilities.CreateLoggerFactory(out _logger);
2419

25-
public void Dispose()
26-
{
27-
_metering.Dispose();
28-
_loggerFactory.Dispose();
29-
}
20+
public void Dispose() => _loggerFactory.Dispose();
3021

3122
[Fact]
3223
public void Meter_Ok()
@@ -113,6 +104,8 @@ public void WriteEvent_LoggingWithoutInstanceName_Ok()
113104
[Theory]
114105
public void WriteEvent_EnsureSeverityRespected(ResilienceEventSeverity severity, LogLevel logLevel)
115106
{
107+
using var metering = TestUtilities.EnablePollyMetering(_events);
108+
116109
var telemetry = Create();
117110
ReportEvent(telemetry, null, severity: severity);
118111

@@ -184,6 +177,7 @@ public void WriteExecutionAttempt_NotEnabled_EnsureNotLogged()
184177
[Theory]
185178
public void WriteEvent_MeteringWithoutEnrichers_Ok(bool noOutcome, bool exception)
186179
{
180+
using var metering = TestUtilities.EnablePollyMetering(_events);
187181
var telemetry = Create();
188182
Outcome<object>? outcome = noOutcome switch
189183
{
@@ -231,6 +225,7 @@ public void WriteEvent_MeteringWithoutEnrichers_Ok(bool noOutcome, bool exceptio
231225
[Theory]
232226
public void WriteExecutionAttemptEvent_Metering_Ok(bool noOutcome, bool exception)
233227
{
228+
using var metering = TestUtilities.EnablePollyMetering(_events);
234229
var telemetry = Create();
235230
var attemptArg = new ExecutionAttemptArguments(5, TimeSpan.FromSeconds(50), true);
236231
Outcome<object>? outcome = noOutcome switch
@@ -279,8 +274,7 @@ public void WriteExecutionAttemptEvent_Metering_Ok(bool noOutcome, bool exceptio
279274
[Fact]
280275
public void WriteExecutionAttemptEvent_ShouldBeSkipped()
281276
{
282-
_metering.Dispose();
283-
_metering = TestUtilities.EnablePollyMetering(_events, _ => false);
277+
using var metering = TestUtilities.EnablePollyMetering(_events, _ => false);
284278

285279
var telemetry = Create();
286280
var attemptArg = new ExecutionAttemptArguments(5, TimeSpan.FromSeconds(50), true);
@@ -295,6 +289,8 @@ public void WriteExecutionAttemptEvent_ShouldBeSkipped()
295289
[Theory]
296290
public void WriteEvent_MeteringWithEnrichers_Ok(int count)
297291
{
292+
using var metering = TestUtilities.EnablePollyMetering(_events);
293+
298294
const int DefaultDimensions = 7;
299295

300296
var telemetry = Create(new[]
@@ -329,6 +325,7 @@ public void WriteEvent_MeteringWithEnrichers_Ok(int count)
329325
[Fact]
330326
public void WriteEvent_MeteringWithoutBuilderInstance_Ok()
331327
{
328+
using var metering = TestUtilities.EnablePollyMetering(_events);
332329
var telemetry = Create();
333330
ReportEvent(telemetry, null, instanceName: null);
334331
var events = GetEvents("resilience-events")[0].Should().NotContainKey("pipeline-instance");
@@ -413,6 +410,8 @@ public void PipelineExecution_NoOutcome_Logged()
413410
[Theory]
414411
public void PipelineExecution_Metered(bool healthy, bool exception)
415412
{
413+
using var metering = TestUtilities.EnablePollyMetering(_events);
414+
416415
var healthString = healthy ? "Healthy" : "Unhealthy";
417416
var context = ResilienceContextPool.Shared.Get("op-key").WithResultType<int>();
418417
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)
472471
[Fact]
473472
public void PipelineExecuted_ShouldBeSkipped()
474473
{
475-
_metering.Dispose();
476-
_metering = TestUtilities.EnablePollyMetering(_events, _ => false);
474+
using var metering = TestUtilities.EnablePollyMetering(_events, _ => false);
477475

478476
var telemetry = Create();
479477
var attemptArg = new PipelineExecutedArguments(TimeSpan.FromSeconds(50));

0 commit comments

Comments
 (0)