diff --git a/docs/chaos/behavior.md b/docs/chaos/behavior.md index b931cf7d79b..de4d1f80b45 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 { BehaviorGenerator = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05 }; @@ -29,7 +28,6 @@ var optionsWithBehaviorGenerator = new ChaosBehaviorStrategyOptions var optionsOnBehaviorInjected = new ChaosBehaviorStrategyOptions { BehaviorGenerator = 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 { BehaviorGenerator = 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..25458bbf2b2 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -72,11 +72,19 @@ 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 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. + | 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. | | `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. | +> [!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 f7e1a71e9bc..b5d9ddc939c 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(); @@ -103,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 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/Polly.Core/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensions.cs index 1a0723e3e7b..d84572fecbd 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, BehaviorGenerator = args => behavior(args.Context.CancellationToken) }); 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/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 = (_) => { diff --git a/src/Snippets/Docs/Chaos.Behavior.cs b/src/Snippets/Docs/Chaos.Behavior.cs index 3c5d2a2bd44..bfedb1a4111 100644 --- a/src/Snippets/Docs/Chaos.Behavior.cs +++ b/src/Snippets/Docs/Chaos.Behavior.cs @@ -15,7 +15,6 @@ public static void BehaviorUsage() var optionsWithBehaviorGenerator = new ChaosBehaviorStrategyOptions { BehaviorGenerator = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05 }; @@ -23,7 +22,6 @@ public static void BehaviorUsage() var optionsOnBehaviorInjected = new ChaosBehaviorStrategyOptions { BehaviorGenerator = static args => RestartRedisAsync(args.Context.CancellationToken), - Enabled = true, InjectionRate = 0.05, OnBehaviorInjected = static args => { @@ -53,7 +51,6 @@ public static void BehaviorUsage() .AddChaosBehavior(new ChaosBehaviorStrategyOptions // Chaos strategies are usually placed as the last ones in the pipeline { BehaviorGenerator = 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(); diff --git a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorPipelineBuilderExtensionsTests.cs index a90fd463ee1..1fbb664583a 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, BehaviorGenerator = (_) => default }) diff --git a/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyOptionsTests.cs b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyOptionsTests.cs index 7c3188e0244..118c7f8cdf0 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/Behavior/ChaosBehaviorStrategyTests.cs b/test/Polly.Core.Tests/Simmy/Behavior/ChaosBehaviorStrategyTests.cs index cc1195eb43a..3bbb287c604 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.BehaviorGenerator = (_) => { _behaviorGeneratorExecuted = 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.BehaviorGenerator = (_) => { _behaviorGeneratorExecuted = 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.BehaviorGenerator = (_) => { @@ -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.BehaviorGenerator = (_) => { 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/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/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/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/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/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/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(); 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) };