From 72588cc88bd54ad341f81970c77ecea847edd4a9 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 17 Sep 2024 18:10:16 +0100 Subject: [PATCH 01/13] Update cake tools - Bump xunit.runner.console to 2.9.0. - Bump dotnet-stryker to 4.2.0. --- build.cake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.cake b/build.cake index 0b57c2700dd..e2ee73da6be 100644 --- a/build.cake +++ b/build.cake @@ -9,8 +9,8 @@ var configuration = Argument("configuration", "Release"); // EXTERNAL NUGET TOOLS ////////////////////////////////////////////////////////////////////// -#Tool "xunit.runner.console&version=2.8.1" -#Tool "dotnet-stryker&version=4.0.6" +#Tool "xunit.runner.console&version=2.9.0" +#Tool "dotnet-stryker&version=4.2.0" ////////////////////////////////////////////////////////////////////// // EXTERNAL NUGET LIBRARIES From bb45edf615f63727049651d1c1248fac687bcbea Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 09:31:26 +0100 Subject: [PATCH 02/13] Fix test - Fix the options from DI not being passed through to the strategy. - Assert that the strategy isn't null when retrieved. --- .../ReloadableResiliencePipelineTests.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs index 2265d3c10a2..b4dacecc990 100644 --- a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs +++ b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NSubstitute; -using Polly.DependencyInjection; using Polly.Registry; using Polly.Telemetry; @@ -20,18 +19,21 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) var resList = new List(); var reloadableConfig = new ReloadableConfiguration(); reloadableConfig.Reload(new() { { "tag", "initial-tag" } }); - var builder = new ConfigurationBuilder().Add(reloadableConfig); var fakeListener = new FakeTelemetryListener(); + var configuration = new ConfigurationBuilder() + .Add(reloadableConfig) + .Build(); + var services = new ServiceCollection(); if (name == null) { - services.Configure(builder.Build()); + services.Configure(configuration); } else { - services.Configure(name, builder.Build()); + services.Configure(name, configuration); } services.Configure(options => options.TelemetryListeners.Add(fakeListener)); @@ -40,6 +42,8 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) builder.InstanceName = "my-instance"; var options = context.GetOptions(name); + options.Should().NotBeNull(); + context.EnableReloads(name); builder.AddStrategy(_ => @@ -48,7 +52,7 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) resList.Add(res); return new ReloadableStrategy(options.Tag, res); }, - new ReloadableStrategyOptions()); + options); }); var serviceProvider = services.BuildServiceProvider(); From 47fe32c6603a71ab389759ee3393f456e5e34679 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 10:34:00 +0100 Subject: [PATCH 03/13] Remove redundant branch - Remove redundant branch because when the key is null it uses the default key, which is what `CurrentValue` does anyway. - Assert that the correct options instance is retrieved. --- .../DependencyInjection/AddResiliencePipelineContext.cs | 3 +-- .../ReloadableResiliencePipelineTests.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs b/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs index 8d358b45f11..a7b6ffe3729 100644 --- a/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs +++ b/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs @@ -61,8 +61,7 @@ internal AddResiliencePipelineContext(ConfigureBuilderContext registryCont public TOptions GetOptions<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions>(string? name = null) { var monitor = ServiceProvider.GetRequiredService>(); - - return name == null ? monitor.CurrentValue : monitor.Get(name); + return monitor.Get(name); } /// diff --git a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs index b4dacecc990..0f0d098622d 100644 --- a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs +++ b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs @@ -29,11 +29,13 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) if (name == null) { - services.Configure(configuration); + services.Configure(configuration) + .Configure(options => options.Name = name); } else { - services.Configure(name, configuration); + services.Configure(name, configuration) + .Configure(name, options => options.Name = name); } services.Configure(options => options.TelemetryListeners.Add(fakeListener)); @@ -43,6 +45,7 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) var options = context.GetOptions(name); options.Should().NotBeNull(); + options.Name.Should().Be(name); context.EnableReloads(name); @@ -119,6 +122,8 @@ protected override ValueTask> ExecuteCore( public class ReloadableStrategyOptions : ResilienceStrategyOptions { public string Tag { get; set; } = string.Empty; + + public string? Name { get; set; } } private class ReloadableConfiguration : ConfigurationProvider, IConfigurationSource From 4628df3437e72067556533e1dc8bffdd25acf0eb Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 10:44:37 +0100 Subject: [PATCH 04/13] Fix CS0108 Rename property to fix Name being overwritten. --- .../ReloadableResiliencePipelineTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs index 0f0d098622d..9641131d07c 100644 --- a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs +++ b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs @@ -30,12 +30,12 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) if (name == null) { services.Configure(configuration) - .Configure(options => options.Name = name); + .Configure(options => options.OptionsName = name); } else { services.Configure(name, configuration) - .Configure(name, options => options.Name = name); + .Configure(name, options => options.OptionsName = name); } services.Configure(options => options.TelemetryListeners.Add(fakeListener)); @@ -45,7 +45,7 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) var options = context.GetOptions(name); options.Should().NotBeNull(); - options.Name.Should().Be(name); + options.OptionsName.Should().Be(name); context.EnableReloads(name); @@ -123,7 +123,7 @@ public class ReloadableStrategyOptions : ResilienceStrategyOptions { public string Tag { get; set; } = string.Empty; - public string? Name { get; set; } + public string? OptionsName { get; set; } } private class ReloadableConfiguration : ConfigurationProvider, IConfigurationSource From 3b4f0d3730e3d5c77cb912b437d288f7bc89162f Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 11:20:39 +0100 Subject: [PATCH 05/13] Swap TFM order - Start with the newest to see if that fixes Stryker. - Explicitly target Debug for mutation tests. - Add missing `eng` items to the Solution Items. --- Polly.sln | 5 +++++ eng/stryker-config.json | 1 + test/Polly.Specs/Polly.Specs.csproj | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Polly.sln b/Polly.sln index 92a68a4c3c7..fdaf8064e5d 100644 --- a/Polly.sln +++ b/Polly.sln @@ -29,9 +29,14 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "eng", "eng", "{04E3C7C5-31F7-4CD6-8BEC-C1032527D231}" ProjectSection(SolutionItems) = preProject eng\Analyzers.targets = eng\Analyzers.targets + eng\Benchmark.targets = eng\Benchmark.targets + eng\bump-version.ps1 = eng\bump-version.ps1 eng\Common.targets = eng\Common.targets eng\Library.targets = eng\Library.targets + eng\stryker-config.json = eng\stryker-config.json eng\Test.targets = eng\Test.targets + eng\update-baselines.ps1 = eng\update-baselines.ps1 + eng\update-changelog.ps1 = eng\update-changelog.ps1 EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polly.Core.Benchmarks", "bench\Polly.Core.Benchmarks\Polly.Core.Benchmarks.csproj", "{CC306C35-E3BC-4F0B-AB8C-B9D4C82DC3DE}" diff --git a/eng/stryker-config.json b/eng/stryker-config.json index 02ac44f8f01..fe485b07db4 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -18,6 +18,7 @@ "block", "statement" ], + "configuration": "Debug", "target-framework": "net8.0", "thresholds": { "high": 100, diff --git a/test/Polly.Specs/Polly.Specs.csproj b/test/Polly.Specs/Polly.Specs.csproj index 6550cca3845..1b55daa6198 100644 --- a/test/Polly.Specs/Polly.Specs.csproj +++ b/test/Polly.Specs/Polly.Specs.csproj @@ -1,7 +1,7 @@  - net6.0;net8.0 + net8.0;net6.0 $(TargetFrameworks);net481 enable Test From 174e34e9a92535728901cd421c0aa10169c751bb Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 11:52:51 +0100 Subject: [PATCH 06/13] Enable dev mode Enable dev mode for Stryker to try and work out why Polly.Specs mutation tests are failing. --- eng/stryker-config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/stryker-config.json b/eng/stryker-config.json index fe485b07db4..278f49f9044 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -19,6 +19,7 @@ "statement" ], "configuration": "Debug", + "dev-mode": true, "target-framework": "net8.0", "thresholds": { "high": 100, From db16deda5c19ce7dba99db825a46d559f1814765 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 12:33:17 +0100 Subject: [PATCH 07/13] Fix dev-mode Can only be enabled on the command-line, not in the configuration file. --- build.cake | 2 +- eng/stryker-config.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build.cake b/build.cake index e2ee73da6be..0a59e8e53d5 100644 --- a/build.cake +++ b/build.cake @@ -201,7 +201,7 @@ Task("__RunMutationTests") Information($"Running mutation tests for '{proj}'. Test Project: '{testProj}'"); - var args = $"{strykerPath} --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project}"; + var args = $"{strykerPath} --dev-mode true --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project}"; var result = StartProcess("dotnet", args); if (result != 0) diff --git a/eng/stryker-config.json b/eng/stryker-config.json index 278f49f9044..fe485b07db4 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -19,7 +19,6 @@ "statement" ], "configuration": "Debug", - "dev-mode": true, "target-framework": "net8.0", "thresholds": { "high": 100, From 4b03bdf8125a8e3fde9ac8a203f0a13680da2bf8 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 12:44:58 +0100 Subject: [PATCH 08/13] Fix dev-mode Remove `true`. --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 0a59e8e53d5..9b43d4847a9 100644 --- a/build.cake +++ b/build.cake @@ -201,7 +201,7 @@ Task("__RunMutationTests") Information($"Running mutation tests for '{proj}'. Test Project: '{testProj}'"); - var args = $"{strykerPath} --dev-mode true --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project}"; + var args = $"{strykerPath} --dev-mode --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project}"; var result = StartProcess("dotnet", args); if (result != 0) From 244c20a1150bea3aeb9fdbead8e7d792f5c72c26 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 13:16:37 +0100 Subject: [PATCH 09/13] Output Stryker logs Include logs from Stryker in the mutation reports. --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 9b43d4847a9..beda78f5ae1 100644 --- a/build.cake +++ b/build.cake @@ -201,7 +201,7 @@ Task("__RunMutationTests") Information($"Running mutation tests for '{proj}'. Test Project: '{testProj}'"); - var args = $"{strykerPath} --dev-mode --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project}"; + var args = $"{strykerPath} --dev-mode --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project} --log-to-file {strykerOutput}/styker.log"; var result = StartProcess("dotnet", args); if (result != 0) From 5377ae6003739390091a570bf7870c6880bfd571 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 18 Sep 2024 13:27:28 +0100 Subject: [PATCH 10/13] Fix --log-to-file It's a flag, not an option that you give a path... --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index beda78f5ae1..e28b4b55c18 100644 --- a/build.cake +++ b/build.cake @@ -201,7 +201,7 @@ Task("__RunMutationTests") Information($"Running mutation tests for '{proj}'. Test Project: '{testProj}'"); - var args = $"{strykerPath} --dev-mode --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project} --log-to-file {strykerOutput}/styker.log"; + var args = $"{strykerPath} --dev-mode --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project} --log-to-file"; var result = StartProcess("dotnet", args); if (result != 0) From d3582f0886349b887b3210e0e478bda2b2a91ab7 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Mon, 23 Sep 2024 13:04:49 +0100 Subject: [PATCH 11/13] Remove target-framework See if stryker will work it out for itself. --- eng/stryker-config.json | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/stryker-config.json b/eng/stryker-config.json index fe485b07db4..60d48e0e295 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -19,7 +19,6 @@ "statement" ], "configuration": "Debug", - "target-framework": "net8.0", "thresholds": { "high": 100, "low": 100 From 4cf588db5f316b44fa0eec464b93d510fd3637b1 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Mon, 23 Sep 2024 16:15:23 +0100 Subject: [PATCH 12/13] Revert Stryker debugging Revert changes made to try and get Stryker working as it's been confirmed there's a bug. --- build.cake | 2 +- eng/stryker-config.json | 1 + test/Polly.Specs/Polly.Specs.csproj | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build.cake b/build.cake index e28b4b55c18..e2ee73da6be 100644 --- a/build.cake +++ b/build.cake @@ -201,7 +201,7 @@ Task("__RunMutationTests") Information($"Running mutation tests for '{proj}'. Test Project: '{testProj}'"); - var args = $"{strykerPath} --dev-mode --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project} --log-to-file"; + var args = $"{strykerPath} --project {project} --test-project {testProj.FullPath} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project}"; var result = StartProcess("dotnet", args); if (result != 0) diff --git a/eng/stryker-config.json b/eng/stryker-config.json index 60d48e0e295..fe485b07db4 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -19,6 +19,7 @@ "statement" ], "configuration": "Debug", + "target-framework": "net8.0", "thresholds": { "high": 100, "low": 100 diff --git a/test/Polly.Specs/Polly.Specs.csproj b/test/Polly.Specs/Polly.Specs.csproj index 1b55daa6198..6550cca3845 100644 --- a/test/Polly.Specs/Polly.Specs.csproj +++ b/test/Polly.Specs/Polly.Specs.csproj @@ -1,7 +1,7 @@  - net8.0;net6.0 + net6.0;net8.0 $(TargetFrameworks);net481 enable Test From 1ffaf0b43ce24808c2923d01b99e6e608b62a13e Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Mon, 23 Sep 2024 16:15:43 +0100 Subject: [PATCH 13/13] Bump xunit.runner.console Update xunit.runner.console to 2.9.1. --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index e2ee73da6be..1abc468dac3 100644 --- a/build.cake +++ b/build.cake @@ -9,7 +9,7 @@ var configuration = Argument("configuration", "Release"); // EXTERNAL NUGET TOOLS ////////////////////////////////////////////////////////////////////// -#Tool "xunit.runner.console&version=2.9.0" +#Tool "xunit.runner.console&version=2.9.1" #Tool "dotnet-stryker&version=4.2.0" //////////////////////////////////////////////////////////////////////