Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class ResilienceTelemetryDiagnosticSourceTests : IDisposable
private readonly FakeLogger _logger;
private readonly ILoggerFactory _loggerFactory;
private readonly List<MeteringEvent> _events = new();
private readonly IDisposable _metering;
private Action<TelemetryEventArguments>? _onEvent;
private IDisposable _metering;

public ResilienceTelemetryDiagnosticSourceTests()
{
Expand Down Expand Up @@ -290,6 +290,20 @@ public void WriteExecutionAttemptEvent_Metering_Ok(bool noOutcome, bool exceptio
_events.Single(v => v.Name == "execution-attempt-duration").Measurement.Should().Be(50000);
}

[Fact]
public void WriteExecutionAttemptEvent_ShouldBeSkipped()
{
_metering.Dispose();
_metering = TestUtilities.EnablePollyMetering(_events, _ => false);

var telemetry = Create();
var attemptArg = new ExecutionAttemptArguments(5, TimeSpan.FromSeconds(50), true);
ReportEvent(telemetry, Outcome.FromResult<object>(true), context: ResilienceContextPool.Shared.Get("op-key").WithResultType<bool>(), arg: attemptArg);

var events = GetEvents("execution-attempt-duration");
events.Should().HaveCount(0);
}

[InlineData(1)]
[InlineData(100)]
[Theory]
Expand Down
7 changes: 6 additions & 1 deletion test/Polly.TestUtils/TestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static ILoggerFactory CreateLoggerFactory(out FakeLogger logger)
return loggerFactory;
}

public static IDisposable EnablePollyMetering(ICollection<MeteringEvent> events)
public static IDisposable EnablePollyMetering(ICollection<MeteringEvent> events, Predicate<Instrument>? shouldListen = null)
{
var stateStr = Guid.NewGuid().ToString();
var meterListener = new MeterListener
Expand All @@ -61,6 +61,11 @@ public static IDisposable EnablePollyMetering(ICollection<MeteringEvent> events)
{
if (instrument.Meter.Name == "Polly")
{
if (shouldListen is not null && !shouldListen(instrument))
{
return;
}

listener.EnableMeasurementEvents(instrument, stateStr);
}
}
Expand Down