From b354d60804f3de463720a2566151abb2ffadb9e2 Mon Sep 17 00:00:00 2001 From: peter-csala Date: Tue, 23 Jan 2024 10:50:26 +0100 Subject: [PATCH 1/7] Replace enabled default value to true --- src/Polly.Core/Simmy/ChaosStrategyConstants.cs | 2 ++ src/Polly.Core/Simmy/ChaosStrategyOptions.cs | 6 +++--- .../Behavior/ChaosBehaviorStrategyOptionsTests.cs | 2 +- .../Simmy/ChaosStrategyConstantsTests.cs | 13 +++++++++++++ .../Simmy/ChaosStrategyOptionsTTests.cs | 2 +- .../Simmy/ChaosStrategyOptionsTests.cs | 2 +- .../Simmy/Fault/ChaosFaultStrategyOptionsTests.cs | 2 +- .../Latency/ChaosLatencyStrategyOptionsTests.cs | 2 +- .../Outcomes/ChaosOutcomeStrategyOptionsTests.cs | 2 +- 9 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs diff --git a/src/Polly.Core/Simmy/ChaosStrategyConstants.cs b/src/Polly.Core/Simmy/ChaosStrategyConstants.cs index 30f4739c9a7..fb457ff59cc 100644 --- a/src/Polly.Core/Simmy/ChaosStrategyConstants.cs +++ b/src/Polly.Core/Simmy/ChaosStrategyConstants.cs @@ -7,4 +7,6 @@ internal static class ChaosStrategyConstants public const double MaxInjectionThreshold = 1; public const double DefaultInjectionRate = 0.001; + + public const bool DefaultEnabled = true; } diff --git a/src/Polly.Core/Simmy/ChaosStrategyOptions.cs b/src/Polly.Core/Simmy/ChaosStrategyOptions.cs index 3ceb4008f5d..568c0c66d03 100644 --- a/src/Polly.Core/Simmy/ChaosStrategyOptions.cs +++ b/src/Polly.Core/Simmy/ChaosStrategyOptions.cs @@ -30,7 +30,7 @@ public abstract class ChaosStrategyOptions : ResilienceStrategyOptions /// /// /// Defaults to . Either or this property is required. - /// When this property is the is used. + /// When this property is then the property is used. /// public Func>? EnabledGenerator { get; set; } @@ -38,9 +38,9 @@ public abstract class ChaosStrategyOptions : ResilienceStrategyOptions /// Gets or sets a value indicating whether or not the chaos strategy is enabled for a given execution. /// /// - /// Defaults to . Either or this property is required. + /// Defaults to . Either or this property is required. /// - public bool Enabled { get; set; } + public bool Enabled { get; set; } = ChaosStrategyConstants.DefaultEnabled; /// /// Gets or sets the Randomizer generator instance that is used to evaluate the injection rate. diff --git a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyOptionsTests.cs b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyOptionsTests.cs index 00a87287bf8..5083cbfec44 100644 --- a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyOptionsTests.cs @@ -12,7 +12,7 @@ public void Ctor_Ok() { var sut = new ChaosBehaviorStrategyOptions(); sut.Randomizer.Should().NotBeNull(); - sut.Enabled.Should().BeFalse(); + sut.Enabled.Should().BeTrue(); sut.EnabledGenerator.Should().BeNull(); sut.InjectionRate.Should().Be(ChaosStrategyConstants.DefaultInjectionRate); sut.InjectionRateGenerator.Should().BeNull(); diff --git a/test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs b/test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs new file mode 100644 index 00000000000..f180b7a21c7 --- /dev/null +++ b/test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs @@ -0,0 +1,13 @@ +using Polly.Simmy; + +public class ChaosStrategyConstantsTests +{ + [Fact] + public void EnsureDefaults() + { + ChaosStrategyConstants.MinInjectionThreshold.Should().Be(0d); + ChaosStrategyConstants.MaxInjectionThreshold.Should().Be(1d); + ChaosStrategyConstants.DefaultInjectionRate.Should().Be(0.001d); + ChaosStrategyConstants.DefaultEnabled.Should().BeTrue(); + } +} diff --git a/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTTests.cs b/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTTests.cs index db2d9a609d8..ef609231886 100644 --- a/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTTests.cs +++ b/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTTests.cs @@ -12,7 +12,7 @@ public void Ctor_Ok() var sut = new TestChaosStrategyOptions(); sut.Randomizer.Should().NotBeNull(); - sut.Enabled.Should().BeFalse(); + sut.Enabled.Should().BeTrue(); sut.EnabledGenerator.Should().BeNull(); sut.InjectionRate.Should().Be(ChaosStrategyConstants.DefaultInjectionRate); sut.InjectionRateGenerator.Should().BeNull(); diff --git a/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTests.cs b/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTests.cs index 21c08640fdd..1a43bc8e7e0 100644 --- a/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/ChaosStrategyOptionsTests.cs @@ -11,7 +11,7 @@ public void Ctor_Ok() var sut = new TestChaosStrategyOptions(); sut.Randomizer.Should().NotBeNull(); - sut.Enabled.Should().BeFalse(); + sut.Enabled.Should().BeTrue(); sut.EnabledGenerator.Should().BeNull(); sut.InjectionRate.Should().Be(ChaosStrategyConstants.DefaultInjectionRate); sut.InjectionRateGenerator.Should().BeNull(); diff --git a/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyOptionsTests.cs b/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyOptionsTests.cs index 8dcc4cf9bd5..60f7a976f59 100644 --- a/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyOptionsTests.cs @@ -12,7 +12,7 @@ public void Ctor_Ok() { var sut = new ChaosFaultStrategyOptions(); sut.Randomizer.Should().NotBeNull(); - sut.Enabled.Should().BeFalse(); + sut.Enabled.Should().BeTrue(); sut.EnabledGenerator.Should().BeNull(); sut.InjectionRate.Should().Be(ChaosStrategyConstants.DefaultInjectionRate); sut.InjectionRateGenerator.Should().BeNull(); diff --git a/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyOptionsTests.cs b/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyOptionsTests.cs index d90b257888e..5d84a4d287f 100644 --- a/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyOptionsTests.cs @@ -10,7 +10,7 @@ public void Ctor_Ok() { var sut = new ChaosLatencyStrategyOptions(); sut.Randomizer.Should().NotBeNull(); - sut.Enabled.Should().BeFalse(); + sut.Enabled.Should().BeTrue(); sut.EnabledGenerator.Should().BeNull(); sut.InjectionRate.Should().Be(ChaosStrategyConstants.DefaultInjectionRate); sut.InjectionRateGenerator.Should().BeNull(); diff --git a/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyOptionsTests.cs b/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyOptionsTests.cs index a50aa559602..c8470d4c2de 100644 --- a/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyOptionsTests.cs @@ -10,7 +10,7 @@ public void Ctor_Ok() { var sut = new ChaosOutcomeStrategyOptions(); sut.Randomizer.Should().NotBeNull(); - sut.Enabled.Should().BeFalse(); + sut.Enabled.Should().BeTrue(); sut.EnabledGenerator.Should().BeNull(); sut.InjectionRate.Should().Be(ChaosStrategyConstants.DefaultInjectionRate); sut.InjectionRateGenerator.Should().BeNull(); From fb4b756121f397db6637bd9504ba0fce146c8c4a Mon Sep 17 00:00:00 2001 From: peter-csala Date: Tue, 23 Jan 2024 11:19:56 +0100 Subject: [PATCH 2/7] Remove enabled true from code samples --- docs/chaos/behavior.md | 3 --- docs/chaos/fault.md | 4 ---- docs/chaos/index.md | 2 +- docs/chaos/latency.md | 4 ---- docs/chaos/outcome.md | 3 --- src/Snippets/Docs/Chaos.Behavior.cs | 3 --- src/Snippets/Docs/Chaos.Fault.cs | 4 ---- src/Snippets/Docs/Chaos.Latency.cs | 4 ---- src/Snippets/Docs/Chaos.Outcome.cs | 3 --- 9 files changed, 1 insertion(+), 29 deletions(-) diff --git a/docs/chaos/behavior.md b/docs/chaos/behavior.md index 78f012a3775..b34c3bfd1ff 100644 --- a/docs/chaos/behavior.md +++ b/docs/chaos/behavior.md @@ -21,7 +21,6 @@ The behavior chaos strategy is designed to inject custom behaviors into system o var optionsWithBehaviorGenerator = new ChaosBehaviorStrategyOptions { BehaviorAction = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05 }; @@ -29,7 +28,6 @@ var optionsWithBehaviorGenerator = new ChaosBehaviorStrategyOptions var optionsOnBehaviorInjected = new ChaosBehaviorStrategyOptions { BehaviorAction = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05, OnBehaviorInjected = static args => { @@ -63,7 +61,6 @@ var pipeline = new ResiliencePipelineBuilder() .AddChaosBehavior(new ChaosBehaviorStrategyOptions // Chaos strategies are usually placed as the last ones in the pipeline { BehaviorAction = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05 }) .Build(); diff --git a/docs/chaos/fault.md b/docs/chaos/fault.md index a96ae107242..2b55744235e 100644 --- a/docs/chaos/fault.md +++ b/docs/chaos/fault.md @@ -23,7 +23,6 @@ var optionsBasic = new ChaosFaultStrategyOptions FaultGenerator = new FaultGenerator() .AddException() // Uses default constructor .AddException(() => new TimeoutException("Chaos timeout injected.")), // Custom exception generator - Enabled = true, InjectionRate = 0.1 }; @@ -43,7 +42,6 @@ var optionsWithFaultGenerator = new ChaosFaultStrategyOptions return new ValueTask(exception); }, - Enabled = true, InjectionRate = 0.1 }; @@ -51,7 +49,6 @@ var optionsWithFaultGenerator = new ChaosFaultStrategyOptions var optionsOnFaultInjected = new ChaosFaultStrategyOptions { FaultGenerator = new FaultGenerator().AddException(), - Enabled = true, InjectionRate = 0.1, OnFaultInjected = static args => { @@ -85,7 +82,6 @@ var pipeline = new ResiliencePipelineBuilder() .AddChaosFault(new ChaosFaultStrategyOptions // Chaos strategies are usually placed as the last ones in the pipeline { FaultGenerator = static args => new ValueTask(new InvalidOperationException("Dummy exception")), - Enabled = true, InjectionRate = 0.1 }) .Build(); diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 0d7d4d471d3..fed279f4000 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -76,7 +76,7 @@ All the strategies' options implement the [`ChaosStrategyOptions`](xref:Polly.Si |--------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `InjectionRate` | 0.001 | 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. | +| `Enabled` | `true` | Determines whether the strategy is enabled or not. | | `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 f7e1a71e9bc..870e63a9423 100644 --- a/docs/chaos/latency.md +++ b/docs/chaos/latency.md @@ -25,7 +25,6 @@ var optionsDefault = new ChaosLatencyStrategyOptions(); var basicOptions = new ChaosLatencyStrategyOptions { Latency = TimeSpan.FromSeconds(30), - Enabled = true, InjectionRate = 0.1 }; @@ -45,7 +44,6 @@ var optionsWithLatencyGenerator = new ChaosLatencyStrategyOptions return new ValueTask(latency); }, - Enabled = true, InjectionRate = 0.1 }; @@ -53,7 +51,6 @@ var optionsWithLatencyGenerator = new ChaosLatencyStrategyOptions var optionsOnLatencyInjected = new ChaosLatencyStrategyOptions { Latency = TimeSpan.FromSeconds(30), - Enabled = true, InjectionRate = 0.1, OnLatencyInjected = static args => { @@ -88,7 +85,6 @@ var pipeline = new ResiliencePipelineBuilder() .AddChaosLatency(new ChaosLatencyStrategyOptions // Chaos strategies are usually placed as the last ones in the pipeline { Latency = TimeSpan.FromSeconds(10), - Enabled = true, InjectionRate = 0.1 }) .Build(); diff --git a/docs/chaos/outcome.md b/docs/chaos/outcome.md index 3203ef92284..5946c9e7a4e 100644 --- a/docs/chaos/outcome.md +++ b/docs/chaos/outcome.md @@ -25,7 +25,6 @@ var optionsWithResultGenerator = new ChaosOutcomeStrategyOptions new HttpResponseMessage(HttpStatusCode.TooManyRequests)) .AddResult(() => new HttpResponseMessage(HttpStatusCode.InternalServerError)) .AddException(() => new HttpRequestException("Chaos request exception.")), - Enabled = true, InjectionRate = 0.1 }; @@ -34,7 +33,6 @@ var optionsOnBehaviorInjected = new ChaosOutcomeStrategyOptions() .AddResult(() => new HttpResponseMessage(HttpStatusCode.InternalServerError)), - Enabled = true, InjectionRate = 0.1, OnOutcomeInjected = static args => { @@ -76,7 +74,6 @@ var pipeline = new ResiliencePipelineBuilder() var response = new HttpResponseMessage(HttpStatusCode.InternalServerError); return new ValueTask?>(Outcome.FromResult(response)); }, - Enabled = true, InjectionRate = 0.1 }) .Build(); diff --git a/src/Snippets/Docs/Chaos.Behavior.cs b/src/Snippets/Docs/Chaos.Behavior.cs index 91088a51fc7..dfd2e466e5b 100644 --- a/src/Snippets/Docs/Chaos.Behavior.cs +++ b/src/Snippets/Docs/Chaos.Behavior.cs @@ -14,7 +14,6 @@ public static void BehaviorUsage() var optionsWithBehaviorGenerator = new ChaosBehaviorStrategyOptions { BehaviorAction = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05 }; @@ -22,7 +21,6 @@ public static void BehaviorUsage() var optionsOnBehaviorInjected = new ChaosBehaviorStrategyOptions { BehaviorAction = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05, OnBehaviorInjected = static args => { @@ -52,7 +50,6 @@ public static void BehaviorUsage() .AddChaosBehavior(new ChaosBehaviorStrategyOptions // Chaos strategies are usually placed as the last ones in the pipeline { BehaviorAction = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05 }) .Build(); diff --git a/src/Snippets/Docs/Chaos.Fault.cs b/src/Snippets/Docs/Chaos.Fault.cs index 0e36be8071f..44e0278355c 100644 --- a/src/Snippets/Docs/Chaos.Fault.cs +++ b/src/Snippets/Docs/Chaos.Fault.cs @@ -18,7 +18,6 @@ public static void FaultUsage() FaultGenerator = new FaultGenerator() .AddException() // Uses default constructor .AddException(() => new TimeoutException("Chaos timeout injected.")), // Custom exception generator - Enabled = true, InjectionRate = 0.1 }; @@ -38,7 +37,6 @@ public static void FaultUsage() return new ValueTask(exception); }, - Enabled = true, InjectionRate = 0.1 }; @@ -46,7 +44,6 @@ public static void FaultUsage() var optionsOnFaultInjected = new ChaosFaultStrategyOptions { FaultGenerator = new FaultGenerator().AddException(), - Enabled = true, InjectionRate = 0.1, OnFaultInjected = static args => { @@ -76,7 +73,6 @@ public static void FaultUsage() .AddChaosFault(new ChaosFaultStrategyOptions // Chaos strategies are usually placed as the last ones in the pipeline { FaultGenerator = static args => new ValueTask(new InvalidOperationException("Dummy exception")), - Enabled = true, InjectionRate = 0.1 }) .Build(); diff --git a/src/Snippets/Docs/Chaos.Latency.cs b/src/Snippets/Docs/Chaos.Latency.cs index 545c04e06de..9019d85b68a 100644 --- a/src/Snippets/Docs/Chaos.Latency.cs +++ b/src/Snippets/Docs/Chaos.Latency.cs @@ -19,7 +19,6 @@ public static void LatencyUsage() var basicOptions = new ChaosLatencyStrategyOptions { Latency = TimeSpan.FromSeconds(30), - Enabled = true, InjectionRate = 0.1 }; @@ -39,7 +38,6 @@ public static void LatencyUsage() return new ValueTask(latency); }, - Enabled = true, InjectionRate = 0.1 }; @@ -47,7 +45,6 @@ public static void LatencyUsage() var optionsOnLatencyInjected = new ChaosLatencyStrategyOptions { Latency = TimeSpan.FromSeconds(30), - Enabled = true, InjectionRate = 0.1, OnLatencyInjected = static args => { @@ -78,7 +75,6 @@ public static void LatencyUsage() .AddChaosLatency(new ChaosLatencyStrategyOptions // Chaos strategies are usually placed as the last ones in the pipeline { Latency = TimeSpan.FromSeconds(10), - Enabled = true, InjectionRate = 0.1 }) .Build(); diff --git a/src/Snippets/Docs/Chaos.Outcome.cs b/src/Snippets/Docs/Chaos.Outcome.cs index 1eec9c5ce91..a8c004a0a81 100644 --- a/src/Snippets/Docs/Chaos.Outcome.cs +++ b/src/Snippets/Docs/Chaos.Outcome.cs @@ -20,7 +20,6 @@ public static void OutcomeUsage() .AddResult(() => new HttpResponseMessage(HttpStatusCode.TooManyRequests)) .AddResult(() => new HttpResponseMessage(HttpStatusCode.InternalServerError)) .AddException(() => new HttpRequestException("Chaos request exception.")), - Enabled = true, InjectionRate = 0.1 }; @@ -29,7 +28,6 @@ public static void OutcomeUsage() { OutcomeGenerator = new OutcomeGenerator() .AddResult(() => new HttpResponseMessage(HttpStatusCode.InternalServerError)), - Enabled = true, InjectionRate = 0.1, OnOutcomeInjected = static args => { @@ -67,7 +65,6 @@ public static void OutcomeUsage() var response = new HttpResponseMessage(HttpStatusCode.InternalServerError); return new ValueTask?>(Outcome.FromResult(response)); }, - Enabled = true, InjectionRate = 0.1 }) .Build(); From fb7752e4e8eb3f3a445504e784cad6caed225cd8 Mon Sep 17 00:00:00 2001 From: peter-csala Date: Tue, 23 Jan 2024 11:20:31 +0100 Subject: [PATCH 3/7] Remove enabled true from extension methods --- .../Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensions.cs | 1 - .../Simmy/Fault/ChaosFaultPipelineBuilderExtensions.cs | 1 - .../Simmy/Latency/ChaosLatencyPipelineBuilderExtensions.cs | 1 - .../Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensions.cs | 1 - 4 files changed, 4 deletions(-) diff --git a/src/Polly.Core/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensions.cs index 35eff9cba36..d984528469b 100644 --- a/src/Polly.Core/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensions.cs +++ b/src/Polly.Core/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensions.cs @@ -26,7 +26,6 @@ public static TBuilder AddChaosBehavior(this TBuilder builder, double return builder.AddChaosBehavior(new ChaosBehaviorStrategyOptions { - Enabled = true, InjectionRate = injectionRate, BehaviorAction = args => behavior(args.Context.CancellationToken) }); diff --git a/src/Polly.Core/Simmy/Fault/ChaosFaultPipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Fault/ChaosFaultPipelineBuilderExtensions.cs index 52fb4e2af31..a0acd43691c 100644 --- a/src/Polly.Core/Simmy/Fault/ChaosFaultPipelineBuilderExtensions.cs +++ b/src/Polly.Core/Simmy/Fault/ChaosFaultPipelineBuilderExtensions.cs @@ -21,7 +21,6 @@ public static TBuilder AddChaosFault(this TBuilder builder, double inj { builder.AddChaosFault(new ChaosFaultStrategyOptions { - Enabled = true, InjectionRate = injectionRate, FaultGenerator = (_) => new ValueTask(faultGenerator()) }); diff --git a/src/Polly.Core/Simmy/Latency/ChaosLatencyPipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Latency/ChaosLatencyPipelineBuilderExtensions.cs index fbd6c7d88e9..48bf7d34ffe 100644 --- a/src/Polly.Core/Simmy/Latency/ChaosLatencyPipelineBuilderExtensions.cs +++ b/src/Polly.Core/Simmy/Latency/ChaosLatencyPipelineBuilderExtensions.cs @@ -26,7 +26,6 @@ public static TBuilder AddChaosLatency(this TBuilder builder, double i return builder.AddChaosLatency(new ChaosLatencyStrategyOptions { - Enabled = true, InjectionRate = injectionRate, Latency = latency }); diff --git a/src/Polly.Core/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensions.cs index 757e87c5ccf..8f7818aa055 100644 --- a/src/Polly.Core/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensions.cs +++ b/src/Polly.Core/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensions.cs @@ -25,7 +25,6 @@ public static class ChaosOutcomePipelineBuilderExtensions builder.AddChaosOutcome(new ChaosOutcomeStrategyOptions { - Enabled = true, InjectionRate = injectionRate, OutcomeGenerator = (_) => { From ea45924de11fdfc3d353043da778907aa71eccf3 Mon Sep 17 00:00:00 2001 From: peter-csala Date: Tue, 23 Jan 2024 11:21:34 +0100 Subject: [PATCH 4/7] Update tests related to enabled --- .../Behavior/ChaosBehaviorPipelineBuilderExtensionsTests.cs | 1 - .../Simmy/Behavior/ChaosBehaviorStrategyTests.cs | 4 ---- .../Simmy/Fault/ChaosFaultPipelineBuilderExtensionsTests.cs | 1 - test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyTests.cs | 5 ----- .../Latency/ChaosLatencyPipelineBuilderExtensionsTests.cs | 1 - .../Simmy/Latency/ChaosLatencyStrategyTests.cs | 3 --- .../Outcomes/ChaosOutcomePipelineBuilderExtensionsTests.cs | 1 - .../Simmy/Outcomes/ChaosOutcomeStrategyTests.cs | 3 --- 8 files changed, 19 deletions(-) diff --git a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensionsTests.cs index 6c81201634d..3121d8297fb 100644 --- a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensionsTests.cs @@ -54,7 +54,6 @@ public void AddBehavior_Options_Ok() var sut = new ResiliencePipelineBuilder() .AddChaosBehavior(new ChaosBehaviorStrategyOptions { - Enabled = true, InjectionRate = 1, BehaviorAction = (_) => default }) diff --git a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyTests.cs b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyTests.cs index 983e8434024..7750a7ef1e5 100644 --- a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyTests.cs +++ b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyTests.cs @@ -40,7 +40,6 @@ public void Given_not_enabled_should_not_inject_behavior() public async Task Given_enabled_and_randomly_within_threshold_should_inject_behavior() { _options.InjectionRate = 0.6; - _options.Enabled = true; _options.Randomizer = () => 0.5; _options.BehaviorAction = (_) => { _behaviorActionExecuted = true; return default; }; @@ -56,7 +55,6 @@ public async Task Given_enabled_and_randomly_within_threshold_should_inject_beha public async Task Given_enabled_and_randomly_within_threshold_ensure_on_behavior_injected_called() { _options.InjectionRate = 0.6; - _options.Enabled = true; _options.Randomizer = () => 0.5; _options.BehaviorAction = (_) => { _behaviorActionExecuted = true; return default; }; _options.OnBehaviorInjected = args => @@ -97,7 +95,6 @@ public async Task Given_enabled_and_randomly_not_within_threshold_should_not_inj public async Task Should_inject_behavior_before_executing_user_delegate() { _options.InjectionRate = 0.6; - _options.Enabled = true; _options.Randomizer = () => 0.5; _options.BehaviorAction = (_) => { @@ -119,7 +116,6 @@ public async Task Should_not_execute_user_delegate_when_it_was_cancelled_running { using var cts = new CancellationTokenSource(); _options.InjectionRate = 0.6; - _options.Enabled = true; _options.Randomizer = () => 0.5; _options.BehaviorAction = (_) => { diff --git a/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultPipelineBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultPipelineBuilderExtensionsTests.cs index 76f42f83f03..39d66a73072 100644 --- a/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultPipelineBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultPipelineBuilderExtensionsTests.cs @@ -15,7 +15,6 @@ public class ChaosFaultPipelineBuilderExtensionsTests builder.AddChaosFault(new ChaosFaultStrategyOptions { InjectionRate = 0.6, - Enabled = true, Randomizer = () => 0.5, FaultGenerator = _=> new ValueTask( new InvalidOperationException("Dummy exception.")) }); diff --git a/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyTests.cs b/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyTests.cs index c0ca7011fab..149cb0fa4d0 100644 --- a/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyTests.cs +++ b/test/Polly.Core.Tests/Simmy/Fault/ChaosFaultStrategyTests.cs @@ -27,7 +27,6 @@ public ChaosFaultStrategyTests() new ChaosFaultStrategyOptions { InjectionRate = 1, - Enabled = true, }, "Either Fault or FaultGenerator is required.", typeof(InvalidOperationException) @@ -109,7 +108,6 @@ public async Task Given_enabled_and_randomly_within_threshold_should_inject_faul var options = new ChaosFaultStrategyOptions { InjectionRate = 0.6, - Enabled = true, Randomizer = () => 0.5, FaultGenerator = _ => new ValueTask(fault), OnFaultInjected = args => @@ -144,7 +142,6 @@ public async Task Given_enabled_and_randomly_within_threshold_should_inject_faul var options = new ChaosFaultStrategyOptions { InjectionRate = 0.6, - Enabled = true, Randomizer = () => 0.5, FaultGenerator = _ => new ValueTask(fault), OnFaultInjected = args => @@ -181,7 +178,6 @@ public void Given_enabled_and_randomly_not_within_threshold_should_not_inject_fa var options = new ChaosFaultStrategyOptions { InjectionRate = 0.3, - Enabled = true, Randomizer = () => 0.5, FaultGenerator = _ => new ValueTask(fault) }; @@ -204,7 +200,6 @@ public void Given_enabled_and_randomly_within_threshold_should_not_inject_fault_ var options = new ChaosFaultStrategyOptions { InjectionRate = 0.6, - Enabled = true, Randomizer = () => 0.5, FaultGenerator = (_) => new ValueTask(Task.FromResult(null)) }; diff --git a/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyPipelineBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyPipelineBuilderExtensionsTests.cs index 42b591099e8..69c5a15d250 100644 --- a/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyPipelineBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyPipelineBuilderExtensionsTests.cs @@ -36,7 +36,6 @@ public void AddLatency_Options_Ok() var sut = new ResiliencePipelineBuilder() .AddChaosLatency(new ChaosLatencyStrategyOptions { - Enabled = true, InjectionRate = 1, LatencyGenerator = (_) => new ValueTask(TimeSpan.FromSeconds(30)) }) diff --git a/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyTests.cs b/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyTests.cs index 2930bab5fbf..10d73042440 100644 --- a/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyTests.cs +++ b/test/Polly.Core.Tests/Simmy/Latency/ChaosLatencyStrategyTests.cs @@ -30,7 +30,6 @@ public ChaosLatencyStrategyTests() public async Task Given_enabled_and_randomly_within_threshold_should_inject_latency() { _options.InjectionRate = 0.6; - _options.Enabled = true; _options.Latency = _delay; _options.Randomizer = () => 0.5; _options.OnLatencyInjected = args => @@ -102,7 +101,6 @@ public async Task Given_enabled_and_randomly_not_within_threshold_should_not_inj public async Task Given_latency_is_negative_should_not_inject_latency(double latency) { _options.InjectionRate = 0.6; - _options.Enabled = true; _options.Latency = TimeSpan.FromSeconds(latency); _options.Randomizer = () => 0.5; @@ -131,7 +129,6 @@ public async Task Should_not_execute_user_delegate_when_it_was_cancelled_running { using var cts = new CancellationTokenSource(); _options.InjectionRate = 0.6; - _options.Enabled = true; _options.Randomizer = () => 0.5; _options.LatencyGenerator = (_) => { diff --git a/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensionsTests.cs index 2bfb0afc957..62f8e4f9e00 100644 --- a/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomePipelineBuilderExtensionsTests.cs @@ -15,7 +15,6 @@ public class ChaosOutcomePipelineBuilderExtensionsTests builder.AddChaosOutcome(new ChaosOutcomeStrategyOptions { InjectionRate = 0.6, - Enabled = true, Randomizer = () => 0.5, OutcomeGenerator = (_) => new ValueTask?>(Outcome.FromResult(100)) }); diff --git a/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyTests.cs b/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyTests.cs index b6833f8e0d6..fe75f773905 100644 --- a/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyTests.cs +++ b/test/Polly.Core.Tests/Simmy/Outcomes/ChaosOutcomeStrategyTests.cs @@ -26,7 +26,6 @@ public ChaosOutcomeStrategyTests() new ChaosOutcomeStrategyOptions { InjectionRate = 1, - Enabled = true, }, "Either Outcome or OutcomeGenerator is required.", typeof(InvalidOperationException) @@ -83,7 +82,6 @@ public async Task Given_enabled_and_randomly_within_threshold_should_inject_resu var options = new ChaosOutcomeStrategyOptions { InjectionRate = 0.6, - Enabled = true, Randomizer = () => 0.5, OutcomeGenerator = (_) => new ValueTask?>(Outcome.FromResult(fakeResult)), OnOutcomeInjected = args => @@ -143,7 +141,6 @@ public async Task Given_enabled_and_randomly_within_threshold_should_inject_resu var options = new ChaosOutcomeStrategyOptions { InjectionRate = 0.6, - Enabled = true, Randomizer = () => 0.5, OutcomeGenerator = (_) => new ValueTask?>(nullOutcome) }; From cfb53d3a09bf34658f2c3bcd63c6182f1ffb455c Mon Sep 17 00:00:00 2001 From: peter-csala Date: Tue, 23 Jan 2024 11:26:09 +0100 Subject: [PATCH 5/7] Add note about property precedence --- docs/chaos/index.md | 3 +++ docs/chaos/latency.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index fed279f4000..860270e2fa2 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -79,4 +79,7 @@ All the strategies' options implement the [`ChaosStrategyOptions`](xref:Polly.Si | `Enabled` | `true` | Determines whether the strategy is enabled or not. | | `EnabledGenerator` | `null` | The generator that indicates whether the chaos strategy is enabled for a given execution. | +> [!NOTE] +> If both `Enabled` and `EnabledGenerator` are specified then `Enabled` will be ignored. + [simmy]: https://github.com/Polly-Contrib/Simmy diff --git a/docs/chaos/latency.md b/docs/chaos/latency.md index 870e63a9423..b5d9ddc939c 100644 --- a/docs/chaos/latency.md +++ b/docs/chaos/latency.md @@ -99,6 +99,9 @@ var pipeline = new ResiliencePipelineBuilder() | `LatencyGenerator` | `null` | Generates the latency to inject for a given execution. | | `OnLatencyInjected` | `null` | Action executed when latency is injected. | +> [!NOTE] +> If both `Latency` and `LatencyGenerator` are specified then `Latency` will be ignored. + ## Diagrams ### Normal 🐵 sequence diagram From d8d028cd661dfd1dda7df7316eb7bd7205fea1d5 Mon Sep 17 00:00:00 2001 From: peter-csala Date: Tue, 23 Jan 2024 13:10:19 +0100 Subject: [PATCH 6/7] Add warning about the default value change --- docs/chaos/index.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 860270e2fa2..984887bdbac 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -72,6 +72,11 @@ Chaos strategies (formerly known as Monkey strategies) are in essence a [Resilie All the strategies' options implement the [`ChaosStrategyOptions`](xref:Polly.Simmy.ChaosStrategyOptions) class as it contains the basic configuration for every chaos strategy. +> [!IMPORTANT] +> Please bear in mind that with the V8 API the chaos strategies are enabled by default. So, you can opt-out them one-by-one either via the `Enabled` or via the `EnabledGenerator` property. +> +> In previous Simmy versions you had to explicitly call either the `Enabled` or the `EnabledWhen` method to opt-in a chaos policy. + | Property | Default Value | Description | |--------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `InjectionRate` | 0.001 | 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. | From 35a8688ec7a6421623d5e72497a773bb70ff1597 Mon Sep 17 00:00:00 2001 From: peter-csala <57183693+peter-csala@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:27:10 +0100 Subject: [PATCH 7/7] Update docs/chaos/index.md Co-authored-by: Martin Costello --- docs/chaos/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 984887bdbac..25458bbf2b2 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -73,7 +73,7 @@ Chaos strategies (formerly known as Monkey strategies) are in essence a [Resilie All the strategies' options implement the [`ChaosStrategyOptions`](xref:Polly.Simmy.ChaosStrategyOptions) class as it contains the basic configuration for every chaos strategy. > [!IMPORTANT] -> Please bear in mind that with the V8 API the chaos strategies are enabled by default. So, you can opt-out them one-by-one either via the `Enabled` or via the `EnabledGenerator` property. +> Please bear in mind that with the V8 API the chaos strategies are enabled by default. So, you can opt-out of them one-by-one either via the `Enabled` or via the `EnabledGenerator` property. > > In previous Simmy versions you had to explicitly call either the `Enabled` or the `EnabledWhen` method to opt-in a chaos policy.