Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Aug 11, 2023
1 parent d7d9f3e commit cd54f5e
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,18 @@ public void PipelineExecution_Logged(bool healthy, bool exception)
messages[0].LogLevel.Should().Be(healthy ? LogLevel.Debug : LogLevel.Warning);
}

[Fact]
public void PipelineExecution_NoOutcome_Logged()
{
var context = ResilienceContextPool.Shared.Get("op-key").WithResultType<int>();
var telemetry = Create();

ReportEvent(telemetry, outcome: null, arg: new PipelineExecutedArguments(TimeSpan.FromSeconds(10)), context: context);

var messages = _logger.GetRecords(new EventId(2, "StrategyExecuted")).ToList();
messages[0].Message.Should().Match($"Resilience strategy executed. Source: 'my-builder/builder-instance', Operation Key: 'op-key', Result Type: 'Int32', Result: '', Execution Health: 'Healthy', Execution Time: 10000ms");
}

[InlineData(true, false)]
[InlineData(false, false)]
[InlineData(true, true)]
Expand Down Expand Up @@ -461,6 +473,20 @@ public void PipelineExecution_Metered(bool healthy, bool exception)
}
}

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

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

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

private List<Dictionary<string, object?>> GetEvents(string eventName) => _events.Where(e => e.Name == eventName).Select(v => v.Tags).ToList();

private ResilienceTelemetryDiagnosticSource Create(Action<ICollection<Action<EnrichmentContext>>>? configureEnrichers = null)
Expand Down

0 comments on commit cd54f5e

Please sign in to comment.