From adf651544b64858974bde5fbac25c5911e126f0c Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 12 Apr 2024 09:50:01 +0100 Subject: [PATCH 1/7] Fix IDE0057 warnings Fix IDE0057 warnings identified in #2003. --- src/Polly.Core/Utils/TypeNameFormatter.cs | 8 +++++++- src/Polly/Utilities/KeyHelper.cs | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Polly.Core/Utils/TypeNameFormatter.cs b/src/Polly.Core/Utils/TypeNameFormatter.cs index 57cc143a60..00fe18faf1 100644 --- a/src/Polly.Core/Utils/TypeNameFormatter.cs +++ b/src/Polly.Core/Utils/TypeNameFormatter.cs @@ -17,6 +17,12 @@ public static string Format(Type type) return type.Name; } - return $"{type.Name.Substring(0, type.Name.Length - GenericSuffixLength)}<{Format(args[0])}>"; +#if NET6_0_OR_GREATER + var nameNoAirity = type.Name[..(type.Name.Length - GenericSuffixLength)]; +#else + var nameNoAirity = type.Name.Substring(0, type.Name.Length - GenericSuffixLength); +#endif + + return $"{nameNoAirity}<{Format(args[0])}>"; } } diff --git a/src/Polly/Utilities/KeyHelper.cs b/src/Polly/Utilities/KeyHelper.cs index fc92a4027f..9b2f21e771 100644 --- a/src/Polly/Utilities/KeyHelper.cs +++ b/src/Polly/Utilities/KeyHelper.cs @@ -6,5 +6,9 @@ internal static class KeyHelper private const int GuidPartLength = 8; public static string GuidPart() => +#if NET6_0_OR_GREATER + Guid.NewGuid().ToString()[..GuidPartLength]; +#else Guid.NewGuid().ToString().Substring(0, GuidPartLength); +#endif } From d457e8bbe84b4266a943168a6be3fc004eb0e2fa Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 12 Apr 2024 09:50:28 +0100 Subject: [PATCH 2/7] Suppress xUnit1031 warnings Suppress xUnit1031 warnings in tests that explicitly test synchronous behaviours. --- .../Hedging/Controller/HedgingExecutionContextTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Polly.Core.Tests/Hedging/Controller/HedgingExecutionContextTests.cs b/test/Polly.Core.Tests/Hedging/Controller/HedgingExecutionContextTests.cs index 7058e1fca6..cba6da27d9 100644 --- a/test/Polly.Core.Tests/Hedging/Controller/HedgingExecutionContextTests.cs +++ b/test/Polly.Core.Tests/Hedging/Controller/HedgingExecutionContextTests.cs @@ -141,7 +141,9 @@ public async Task TryWaitForCompletedExecutionAsync_SynchronousExecution_Ok() } var task = context.TryWaitForCompletedExecutionAsync(System.Threading.Timeout.InfiniteTimeSpan).AsTask(); +#pragma warning disable xUnit1031 // Do not use blocking task operations in test method task.Wait(20).Should().BeFalse(); +#pragma warning restore xUnit1031 // Do not use blocking task operations in test method _timeProvider.Advance(TimeSpan.FromDays(1)); await task; context.Tasks[0].AcceptOutcome(); @@ -162,7 +164,9 @@ public async Task TryWaitForCompletedExecutionAsync_HedgedExecution_Ok() var hedgingDelay = TimeSpan.FromSeconds(5); var count = _timeProvider.TimerEntries.Count; var task = context.TryWaitForCompletedExecutionAsync(hedgingDelay).AsTask(); +#pragma warning disable xUnit1031 // Do not use blocking task operations in test method task.Wait(20).Should().BeFalse(); +#pragma warning restore xUnit1031 // Do not use blocking task operations in test method _timeProvider.TimerEntries.Should().HaveCount(count + 1); _timeProvider.TimerEntries.Last().Delay.Should().Be(hedgingDelay); _timeProvider.Advance(TimeSpan.FromDays(1)); @@ -382,7 +386,9 @@ public async Task Complete_EnsurePendingTasksCleaned() await context.TryWaitForCompletedExecutionAsync(System.Threading.Timeout.InfiniteTimeSpan); var pending = context.Tasks[1].ExecutionTaskSafe!; +#pragma warning disable xUnit1031 // Do not use blocking task operations in test method pending.Wait(10).Should().BeFalse(); +#pragma warning restore xUnit1031 // Do not use blocking task operations in test method context.Tasks[0].AcceptOutcome(); await context.DisposeAsync(); From 8583c3b56965a5f357aa6bd588e323041dcce6bb Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 12 Apr 2024 09:52:33 +0100 Subject: [PATCH 3/7] Simplify AoT properties - Remove properties that are implied by `IsAotCompatible=true`. - Only mark as AoT-compatible for `net8.0` where it's actually supported. --- src/Polly.Core/Polly.Core.csproj | 6 +----- src/Polly.Extensions/Polly.Extensions.csproj | 6 +----- src/Polly.RateLimiting/Polly.RateLimiting.csproj | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Polly.Core/Polly.Core.csproj b/src/Polly.Core/Polly.Core.csproj index dc559e6103..87d5cf5f18 100644 --- a/src/Polly.Core/Polly.Core.csproj +++ b/src/Polly.Core/Polly.Core.csproj @@ -11,12 +11,8 @@ true true - - true - true - true + true - true diff --git a/src/Polly.Extensions/Polly.Extensions.csproj b/src/Polly.Extensions/Polly.Extensions.csproj index 2b752a541a..25ff0fd719 100644 --- a/src/Polly.Extensions/Polly.Extensions.csproj +++ b/src/Polly.Extensions/Polly.Extensions.csproj @@ -9,12 +9,8 @@ 100 true - - true - true - true + true - true diff --git a/src/Polly.RateLimiting/Polly.RateLimiting.csproj b/src/Polly.RateLimiting/Polly.RateLimiting.csproj index f06c8a674a..789946e976 100644 --- a/src/Polly.RateLimiting/Polly.RateLimiting.csproj +++ b/src/Polly.RateLimiting/Polly.RateLimiting.csproj @@ -9,12 +9,8 @@ 100 true - - true - true - true + true - true From 209ac6b35adef2547380a72077877d2d40f2a1bb Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 12 Apr 2024 09:52:50 +0100 Subject: [PATCH 4/7] Add missing namespace Fix test not being declared in a namespace. --- test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs b/test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs index f180b7a21c..5eb79df057 100644 --- a/test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs +++ b/test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs @@ -1,5 +1,7 @@ using Polly.Simmy; +namespace Polly.Core.Tests; + public class ChaosStrategyConstantsTests { [Fact] From e7a154c4e701a3b1826fe981da30e4bc26d315a1 Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 12 Apr 2024 09:53:58 +0100 Subject: [PATCH 5/7] Update dependencies - Bump the samples' reference to ourself to the latest version. - Bump `Microsoft.Extensions.TimeProvider.Testing` to 8.4.0. - Use an MSBuild property to allow for easy conditions for multi-targeting. --- Directory.Packages.props | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f886355373..536b384f78 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,8 +1,9 @@ - 8.0.0 true - 8.3.0 + 8.3.1 + 8.0.0 + 8.4.0 @@ -22,7 +23,7 @@ - + From 95505d3801c5dd938d7dae7f39c522f0205a2739 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Fri, 12 Apr 2024 10:19:17 +0100 Subject: [PATCH 6/7] Add Microsoft.Bcl.TimeProvider reference Add package reference to Microsoft.Bcl.TimeProvider as Microsoft.Extensions.TimeProvider.Testing appears to have trimmed the dependency away. --- test/Polly.Core.Tests/Polly.Core.Tests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Polly.Core.Tests/Polly.Core.Tests.csproj b/test/Polly.Core.Tests/Polly.Core.Tests.csproj index b982b9b6ad..b9049a6314 100644 --- a/test/Polly.Core.Tests/Polly.Core.Tests.csproj +++ b/test/Polly.Core.Tests/Polly.Core.Tests.csproj @@ -11,6 +11,7 @@ + From 71fcef209f9d064efb353aa318ffd016b98b6cfa Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Fri, 12 Apr 2024 10:24:22 +0100 Subject: [PATCH 7/7] Add VersionOverride Add `VersionOverride` to fix package downgrade warning. --- test/Polly.Core.Tests/Polly.Core.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Polly.Core.Tests/Polly.Core.Tests.csproj b/test/Polly.Core.Tests/Polly.Core.Tests.csproj index b9049a6314..49fd0884d9 100644 --- a/test/Polly.Core.Tests/Polly.Core.Tests.csproj +++ b/test/Polly.Core.Tests/Polly.Core.Tests.csproj @@ -11,7 +11,7 @@ - +