diff --git a/docs/chaos/index.md b/docs/chaos/index.md index af2034c2ab4..484abccfcff 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -51,6 +51,6 @@ All the strategies' options implement the [`MonkeyStrategyOptions`](xref:Polly.S | `InjectionRate` | 0.001 ms | A decimal between 0 and 1 inclusive. The strategy will inject the chaos, randomly, that proportion of the time, e.g.: if 0.2, twenty percent of calls will be randomly affected; if 0.01, one percent of calls; if 1, all calls. | | `InjectionRateGenerator` | `null` | Generates the injection rate for a given execution, which the value should be between [0, 1] (inclusive). | | `Enabled` | `false` | Determines whether the strategy is enabled or not. | -| `EnabledGenerator` | `null` | The generator that indicates whether the chaos strategy is enabled for a given execution. | +| `EnabledGenerator` | `null` | The generator that indicates whether the chaos strategy is enabled for a given execution. | [simmy]: https://github.com/Polly-Contrib/Simmy diff --git a/docs/chaos/latency.md b/docs/chaos/latency.md index 77a243bf3b5..9fcf430852d 100644 --- a/docs/chaos/latency.md +++ b/docs/chaos/latency.md @@ -48,14 +48,14 @@ var optionsWithLatencyGenerator = new LatencyStrategyOptions }; // To get notifications when a delay is injected -var optionsOnBehaviorInjected = new LatencyStrategyOptions +var optionsOnLatencyInjected = new LatencyStrategyOptions { Latency = TimeSpan.FromSeconds(30), Enabled = true, InjectionRate = 0.1, - OnLatency = static args => + OnLatencyInjected = static args => { - Console.WriteLine($"OnLatency, Latency: {args.Latency}, Operation: {args.Context.OperationKey}."); + Console.WriteLine($"OnLatencyInjected, Latency: {args.Latency}, Operation: {args.Context.OperationKey}."); return default; } }; @@ -95,11 +95,11 @@ var pipeline = new ResiliencePipelineBuilder() ## Defaults -| Property | Default Value | Description | -|--------------------|---------------|--------------------------------------------------------| -| `Latency` | `30 seconds` | A `TimeSpan` indicating the delay to be injected. | -| `LatencyGenerator` | `null` | Generates the latency to inject for a given execution. | -| `OnLatency` | `null` | Action executed when latency is injected. | +| Property | Default Value | Description | +|---------------------|---------------|--------------------------------------------------------| +| `Latency` | `30 seconds` | A `TimeSpan` indicating the delay to be injected. | +| `LatencyGenerator` | `null` | Generates the latency to inject for a given execution. | +| `OnLatencyInjected` | `null` | Action executed when latency is injected. | ## Diagrams diff --git a/src/Polly.Core/PublicAPI.Unshipped.txt b/src/Polly.Core/PublicAPI.Unshipped.txt index cd6bf54fba4..af7eab4a0e0 100644 --- a/src/Polly.Core/PublicAPI.Unshipped.txt +++ b/src/Polly.Core/PublicAPI.Unshipped.txt @@ -55,13 +55,13 @@ Polly.Simmy.Latency.LatencyStrategyOptions.Latency.set -> void Polly.Simmy.Latency.LatencyStrategyOptions.LatencyGenerator.get -> System.Func>? Polly.Simmy.Latency.LatencyStrategyOptions.LatencyGenerator.set -> void Polly.Simmy.Latency.LatencyStrategyOptions.LatencyStrategyOptions() -> void -Polly.Simmy.Latency.LatencyStrategyOptions.OnLatency.get -> System.Func? -Polly.Simmy.Latency.LatencyStrategyOptions.OnLatency.set -> void -Polly.Simmy.Latency.OnLatencyArguments -Polly.Simmy.Latency.OnLatencyArguments.Context.get -> Polly.ResilienceContext! -Polly.Simmy.Latency.OnLatencyArguments.Latency.get -> System.TimeSpan -Polly.Simmy.Latency.OnLatencyArguments.OnLatencyArguments() -> void -Polly.Simmy.Latency.OnLatencyArguments.OnLatencyArguments(Polly.ResilienceContext! context, System.TimeSpan latency) -> void +Polly.Simmy.Latency.LatencyStrategyOptions.OnLatencyInjected.get -> System.Func? +Polly.Simmy.Latency.LatencyStrategyOptions.OnLatencyInjected.set -> void +Polly.Simmy.Latency.OnLatencyInjectedArguments +Polly.Simmy.Latency.OnLatencyInjectedArguments.Context.get -> Polly.ResilienceContext! +Polly.Simmy.Latency.OnLatencyInjectedArguments.Latency.get -> System.TimeSpan +Polly.Simmy.Latency.OnLatencyInjectedArguments.OnLatencyInjectedArguments() -> void +Polly.Simmy.Latency.OnLatencyInjectedArguments.OnLatencyInjectedArguments(Polly.ResilienceContext! context, System.TimeSpan latency) -> void Polly.Simmy.LatencyPipelineBuilderExtensions Polly.Simmy.MonkeyStrategy Polly.Simmy.MonkeyStrategy.MonkeyStrategy(Polly.Simmy.MonkeyStrategyOptions! options) -> void diff --git a/src/Polly.Core/Simmy/Behavior/BehaviorConstants.cs b/src/Polly.Core/Simmy/Behavior/BehaviorConstants.cs index 91341bdb948..188e392f32b 100644 --- a/src/Polly.Core/Simmy/Behavior/BehaviorConstants.cs +++ b/src/Polly.Core/Simmy/Behavior/BehaviorConstants.cs @@ -2,5 +2,7 @@ internal static class BehaviorConstants { - public const string OnBehaviorInjectedEvent = "OnBehaviorInjected"; + public const string DefaultName = "Chaos.Behavior"; + + public const string OnBehaviorInjectedEvent = "Chaos.OnBehavior"; } diff --git a/src/Polly.Core/Simmy/Behavior/BehaviorStrategyOptions.cs b/src/Polly.Core/Simmy/Behavior/BehaviorStrategyOptions.cs index 1541fbc9b3f..84fcb3703ab 100644 --- a/src/Polly.Core/Simmy/Behavior/BehaviorStrategyOptions.cs +++ b/src/Polly.Core/Simmy/Behavior/BehaviorStrategyOptions.cs @@ -7,6 +7,11 @@ namespace Polly.Simmy.Behavior; /// public class BehaviorStrategyOptions : MonkeyStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public BehaviorStrategyOptions() => Name = BehaviorConstants.DefaultName; + /// /// Gets or sets the delegate that's raised when the custom behavior is injected. /// diff --git a/src/Polly.Core/Simmy/Fault/FaultConstants.cs b/src/Polly.Core/Simmy/Fault/FaultConstants.cs index 1e8f325af5b..a38c84a9fcc 100644 --- a/src/Polly.Core/Simmy/Fault/FaultConstants.cs +++ b/src/Polly.Core/Simmy/Fault/FaultConstants.cs @@ -2,5 +2,7 @@ internal static class FaultConstants { - public const string OnFaultInjectedEvent = "OnFaultInjectedEvent"; + public const string DefaultName = "Chaos.Fault"; + + public const string OnFaultInjectedEvent = "Chaos.OnFault"; } diff --git a/src/Polly.Core/Simmy/Fault/FaultStrategyOptions.cs b/src/Polly.Core/Simmy/Fault/FaultStrategyOptions.cs index deb8d61a602..abb10ebd639 100644 --- a/src/Polly.Core/Simmy/Fault/FaultStrategyOptions.cs +++ b/src/Polly.Core/Simmy/Fault/FaultStrategyOptions.cs @@ -7,6 +7,11 @@ namespace Polly.Simmy.Fault; /// public class FaultStrategyOptions : MonkeyStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public FaultStrategyOptions() => Name = FaultConstants.DefaultName; + /// /// Gets or sets the delegate that's raised when the outcome is injected. /// @@ -19,8 +24,7 @@ public class FaultStrategyOptions : MonkeyStrategyOptions /// Gets or sets the fault generator to be injected for a given execution. /// /// - /// Defaults to . Either or this property is required. - /// When this property is the is used. + /// Defaults to . /// [Required] public Func>? FaultGenerator { get; set; } = default!; diff --git a/src/Polly.Core/Simmy/Latency/LatencyChaosStrategy.cs b/src/Polly.Core/Simmy/Latency/LatencyChaosStrategy.cs index 409c9a4881f..cdeb5b8efcb 100644 --- a/src/Polly.Core/Simmy/Latency/LatencyChaosStrategy.cs +++ b/src/Polly.Core/Simmy/Latency/LatencyChaosStrategy.cs @@ -15,13 +15,13 @@ public LatencyChaosStrategy( { Latency = options.Latency; LatencyGenerator = options.LatencyGenerator is not null ? options.LatencyGenerator : (_) => new(options.Latency); - OnLatency = options.OnLatency; + OnLatencyInjected = options.OnLatencyInjected; _telemetry = telemetry; _timeProvider = timeProvider; } - public Func? OnLatency { get; } + public Func? OnLatencyInjected { get; } public Func> LatencyGenerator { get; } @@ -43,14 +43,14 @@ protected internal override async ValueTask> ExecuteCore public class LatencyStrategyOptions : MonkeyStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public LatencyStrategyOptions() => Name = LatencyConstants.DefaultName; + /// /// Gets or sets the delegate that's raised when a delay occurs. /// /// /// Defaults to . /// - public Func? OnLatency { get; set; } + public Func? OnLatencyInjected { get; set; } /// /// Gets or sets the latency generator that generates the delay for a given execution. diff --git a/src/Polly.Core/Simmy/Latency/OnLatencyArguments.cs b/src/Polly.Core/Simmy/Latency/OnLatencyInjectedArguments.cs similarity index 77% rename from src/Polly.Core/Simmy/Latency/OnLatencyArguments.cs rename to src/Polly.Core/Simmy/Latency/OnLatencyInjectedArguments.cs index 9a3896d2904..b82423ede42 100644 --- a/src/Polly.Core/Simmy/Latency/OnLatencyArguments.cs +++ b/src/Polly.Core/Simmy/Latency/OnLatencyInjectedArguments.cs @@ -5,14 +5,14 @@ /// /// Arguments used by the latency chaos strategy to notify that a delayed occurred. /// -public readonly struct OnLatencyArguments +public readonly struct OnLatencyInjectedArguments { /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The context associated with the execution of a user-provided callback. /// The latency that was injected. - public OnLatencyArguments(ResilienceContext context, TimeSpan latency) + public OnLatencyInjectedArguments(ResilienceContext context, TimeSpan latency) { Context = context; Latency = latency; diff --git a/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs b/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs index d061a0579f1..1ac0882db04 100644 --- a/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs +++ b/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs @@ -2,5 +2,7 @@ internal static class OutcomeConstants { - public const string OnOutcomeInjectedEvent = "OnOutcomeInjected"; + public const string DefaultName = "Chaos.Outcome"; + + public const string OnOutcomeInjectedEvent = "Chaos.OnOutcome"; } diff --git a/src/Polly.Core/Simmy/Outcomes/OutcomeStrategyOptions.cs b/src/Polly.Core/Simmy/Outcomes/OutcomeStrategyOptions.cs index fa8f21fddad..31867aafbf2 100644 --- a/src/Polly.Core/Simmy/Outcomes/OutcomeStrategyOptions.cs +++ b/src/Polly.Core/Simmy/Outcomes/OutcomeStrategyOptions.cs @@ -8,6 +8,11 @@ namespace Polly.Simmy.Outcomes; /// The type of the outcome that was injected. public class OutcomeStrategyOptions : MonkeyStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public OutcomeStrategyOptions() => Name = OutcomeConstants.DefaultName; + /// /// Gets or sets the delegate that's invoked when the outcome is injected. /// diff --git a/src/Snippets/Docs/Chaos.Latency.cs b/src/Snippets/Docs/Chaos.Latency.cs index 75fdf174d9e..e1cd6d49f30 100644 --- a/src/Snippets/Docs/Chaos.Latency.cs +++ b/src/Snippets/Docs/Chaos.Latency.cs @@ -42,14 +42,14 @@ public static void LatencyUsage() }; // To get notifications when a delay is injected - var optionsOnBehaviorInjected = new LatencyStrategyOptions + var optionsOnLatencyInjected = new LatencyStrategyOptions { Latency = TimeSpan.FromSeconds(30), Enabled = true, InjectionRate = 0.1, - OnLatency = static args => + OnLatencyInjected = static args => { - Console.WriteLine($"OnLatency, Latency: {args.Latency}, Operation: {args.Context.OperationKey}."); + Console.WriteLine($"OnLatencyInjected, Latency: {args.Latency}, Operation: {args.Context.OperationKey}."); return default; } }; diff --git a/test/Polly.Core.Tests/Simmy/Behavior/BehaviorConstantsTests.cs b/test/Polly.Core.Tests/Simmy/Behavior/BehaviorConstantsTests.cs index e25fffb3fe0..13f0d4a6578 100644 --- a/test/Polly.Core.Tests/Simmy/Behavior/BehaviorConstantsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Behavior/BehaviorConstantsTests.cs @@ -7,6 +7,7 @@ public class BehaviorConstantsTests [Fact] public void EnsureDefaults() { - BehaviorConstants.OnBehaviorInjectedEvent.Should().Be("OnBehaviorInjected"); + BehaviorConstants.DefaultName.Should().Be("Chaos.Behavior"); + BehaviorConstants.OnBehaviorInjectedEvent.Should().Be("Chaos.OnBehavior"); } } diff --git a/test/Polly.Core.Tests/Simmy/Fault/FaultConstantsTests.cs b/test/Polly.Core.Tests/Simmy/Fault/FaultConstantsTests.cs index ffc1cfd1ff4..2a52b8cd2d1 100644 --- a/test/Polly.Core.Tests/Simmy/Fault/FaultConstantsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Fault/FaultConstantsTests.cs @@ -7,6 +7,7 @@ public class FaultConstantsTests [Fact] public void EnsureDefaults() { - FaultConstants.OnFaultInjectedEvent.Should().Be("OnFaultInjectedEvent"); + FaultConstants.DefaultName.Should().Be("Chaos.Fault"); + FaultConstants.OnFaultInjectedEvent.Should().Be("Chaos.OnFault"); } } diff --git a/test/Polly.Core.Tests/Simmy/Latency/LatencyChaosStrategyTests.cs b/test/Polly.Core.Tests/Simmy/Latency/LatencyChaosStrategyTests.cs index 361ab2d75ba..b44aa136e2e 100644 --- a/test/Polly.Core.Tests/Simmy/Latency/LatencyChaosStrategyTests.cs +++ b/test/Polly.Core.Tests/Simmy/Latency/LatencyChaosStrategyTests.cs @@ -32,7 +32,7 @@ public async Task Given_enabled_and_randomly_within_threshold_should_inject_late _options.Enabled = true; _options.Latency = _delay; _options.Randomizer = () => 0.5; - _options.OnLatency = args => + _options.OnLatencyInjected = args => { args.Context.Should().NotBeNull(); args.Context.CancellationToken.IsCancellationRequested.Should().BeFalse(); @@ -51,7 +51,7 @@ public async Task Given_enabled_and_randomly_within_threshold_should_inject_late (after - before).Should().Be(_delay); _args.Should().HaveCount(1); - _args[0].Arguments.Should().BeOfType(); + _args[0].Arguments.Should().BeOfType(); onLatencyExecuted.Should().BeTrue(); } @@ -110,7 +110,7 @@ public async Task Given_latency_is_negative_should_not_inject_latency(double lat _options.Latency = TimeSpan.FromSeconds(latency); _options.Randomizer = () => 0.5; - _options.OnLatency = args => + _options.OnLatencyInjected = args => { args.Context.Should().NotBeNull(); args.Context.CancellationToken.IsCancellationRequested.Should().BeFalse(); diff --git a/test/Polly.Core.Tests/Simmy/Latency/LatencyConstantsTests.cs b/test/Polly.Core.Tests/Simmy/Latency/LatencyConstantsTests.cs index 1d27e28bf8f..b1c3b4462b3 100644 --- a/test/Polly.Core.Tests/Simmy/Latency/LatencyConstantsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Latency/LatencyConstantsTests.cs @@ -7,7 +7,8 @@ public class LatencyConstantsTests [Fact] public void EnsureDefaults() { - LatencyConstants.OnLatencyEvent.Should().Be("OnLatency"); + LatencyConstants.DefaultName.Should().Be("Chaos.Latency"); + LatencyConstants.OnLatencyInjectedEvent.Should().Be("Chaos.OnLatency"); LatencyConstants.DefaultLatency.Should().Be(TimeSpan.FromSeconds(30)); } } diff --git a/test/Polly.Core.Tests/Simmy/Latency/LatencyStrategyOptionsTests.cs b/test/Polly.Core.Tests/Simmy/Latency/LatencyStrategyOptionsTests.cs index 571b5c2df7d..2999b798082 100644 --- a/test/Polly.Core.Tests/Simmy/Latency/LatencyStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Latency/LatencyStrategyOptionsTests.cs @@ -16,6 +16,6 @@ public void Ctor_Ok() sut.InjectionRateGenerator.Should().BeNull(); sut.Latency.Should().Be(LatencyConstants.DefaultLatency); sut.LatencyGenerator.Should().BeNull(); - sut.OnLatency.Should().BeNull(); + sut.OnLatencyInjected.Should().BeNull(); } } diff --git a/test/Polly.Core.Tests/Simmy/Latency/OnLatencyArgumentsTests.cs b/test/Polly.Core.Tests/Simmy/Latency/OnLatencyInjectedArgumentsTests.cs similarity index 58% rename from test/Polly.Core.Tests/Simmy/Latency/OnLatencyArgumentsTests.cs rename to test/Polly.Core.Tests/Simmy/Latency/OnLatencyInjectedArgumentsTests.cs index 5c834634e5f..838ea641690 100644 --- a/test/Polly.Core.Tests/Simmy/Latency/OnLatencyArgumentsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Latency/OnLatencyInjectedArgumentsTests.cs @@ -2,12 +2,12 @@ namespace Polly.Core.Tests.Simmy.Latency; -public class OnLatencyArgumentsTests +public class OnLatencyInjectedArgumentsTests { [Fact] public void Ctor_Ok() { - var args = new OnLatencyArguments(ResilienceContextPool.Shared.Get(), TimeSpan.FromSeconds(10)); + var args = new OnLatencyInjectedArguments(ResilienceContextPool.Shared.Get(), TimeSpan.FromSeconds(10)); args.Context.Should().NotBeNull(); args.Latency.Should().Be(TimeSpan.FromSeconds(10)); } diff --git a/test/Polly.Core.Tests/Simmy/Outcomes/OutcomeConstantsTests.cs b/test/Polly.Core.Tests/Simmy/Outcomes/OutcomeConstantsTests.cs index dcd92910518..f2c085bdd01 100644 --- a/test/Polly.Core.Tests/Simmy/Outcomes/OutcomeConstantsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Outcomes/OutcomeConstantsTests.cs @@ -7,6 +7,7 @@ public class OutcomeConstantsTests [Fact] public void EnsureDefaults() { - OutcomeConstants.OnOutcomeInjectedEvent.Should().Be("OnOutcomeInjected"); + OutcomeConstants.DefaultName.Should().Be("Chaos.Outcome"); + OutcomeConstants.OnOutcomeInjectedEvent.Should().Be("Chaos.OnOutcome"); } }