From 0923fae91afc9f81cde82922630e185add48c370 Mon Sep 17 00:00:00 2001 From: martincostello Date: Thu, 4 Dec 2025 16:37:42 +0000 Subject: [PATCH] .NET 10 preparation Cherrypick some changes from #2531 while that is blocked on a new release of Stryker that supports .NET 10 GA. --- .github/workflows/build.yml | 1 + .github/workflows/mutation-tests.yml | 1 + Directory.Packages.props | 2 +- bench/Polly.Benchmarks/Polly.Benchmarks.csproj | 2 +- src/Polly/Bulkhead/AsyncBulkheadPolicy.cs | 14 ++++++++------ src/Polly/Bulkhead/BulkheadPolicy.cs | 14 ++++++++------ test/Polly.Specs/Polly.Specs.csproj | 2 +- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2cab94f6c9..124d708ea6d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,6 +85,7 @@ jobs: with: dotnet-version: | 8.0.x + 9.0.x - name: Setup .NET SDK uses: actions/setup-dotnet@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5.0.1 diff --git a/.github/workflows/mutation-tests.yml b/.github/workflows/mutation-tests.yml index cb7e0b048c9..c661398a90b 100644 --- a/.github/workflows/mutation-tests.yml +++ b/.github/workflows/mutation-tests.yml @@ -59,6 +59,7 @@ jobs: with: dotnet-version: | 8.0.x + 9.0.x - name: Setup .NET SDK uses: actions/setup-dotnet@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5.0.1 diff --git a/Directory.Packages.props b/Directory.Packages.props index 27c795104b3..76e560ffd00 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -21,7 +21,7 @@ - + diff --git a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj index ff37159c11a..4a36838e4b3 100644 --- a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj +++ b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj @@ -2,7 +2,7 @@ false Exe - net8.0;net9.0 + net9.0;net8.0 enable Benchmark $(NoWarn);CA1822;IDE0060 diff --git a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs index db6fa2e00ad..6b413af058b 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs @@ -10,7 +10,6 @@ public class AsyncBulkheadPolicy : AsyncPolicy, IBulkheadPolicy { private readonly SemaphoreSlim _maxParallelizationSemaphore; private readonly SemaphoreSlim _maxQueuedActionsSemaphore; - private readonly int _maxQueueingActions; private readonly Func _onBulkheadRejectedAsync; internal AsyncBulkheadPolicy( @@ -18,12 +17,14 @@ internal AsyncBulkheadPolicy( int maxQueueingActions, Func onBulkheadRejectedAsync) { - _maxQueueingActions = maxQueueingActions; + MaxQueueingActions = maxQueueingActions; _onBulkheadRejectedAsync = onBulkheadRejectedAsync; (_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions); } + private int MaxQueueingActions { get; } + /// /// Gets the number of slots currently available for executing actions through the bulkhead. /// @@ -32,7 +33,7 @@ internal AsyncBulkheadPolicy( /// /// Gets the number of slots currently available for queuing actions for execution through the bulkhead. /// - public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions); + public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions); /// [DebuggerStepThrough] @@ -78,7 +79,6 @@ public class AsyncBulkheadPolicy : AsyncPolicy, IBulkheadPolic { private readonly SemaphoreSlim _maxParallelizationSemaphore; private readonly SemaphoreSlim _maxQueuedActionsSemaphore; - private readonly int _maxQueueingActions; private readonly Func _onBulkheadRejectedAsync; internal AsyncBulkheadPolicy( @@ -86,12 +86,14 @@ internal AsyncBulkheadPolicy( int maxQueueingActions, Func onBulkheadRejectedAsync) { - _maxQueueingActions = maxQueueingActions; + MaxQueueingActions = maxQueueingActions; _onBulkheadRejectedAsync = onBulkheadRejectedAsync; (_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions); } + private int MaxQueueingActions { get; } + /// [DebuggerStepThrough] protected override Task ImplementationAsync( @@ -123,7 +125,7 @@ protected override Task ImplementationAsync( /// /// Gets the number of slots currently available for queuing actions for execution through the bulkhead. /// - public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions); + public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions); #pragma warning disable CA1063 /// diff --git a/src/Polly/Bulkhead/BulkheadPolicy.cs b/src/Polly/Bulkhead/BulkheadPolicy.cs index 27e04e39b67..96334ca05d0 100644 --- a/src/Polly/Bulkhead/BulkheadPolicy.cs +++ b/src/Polly/Bulkhead/BulkheadPolicy.cs @@ -10,7 +10,6 @@ public class BulkheadPolicy : Policy, IBulkheadPolicy { private readonly SemaphoreSlim _maxParallelizationSemaphore; private readonly SemaphoreSlim _maxQueuedActionsSemaphore; - private readonly int _maxQueueingActions; private readonly Action _onBulkheadRejected; internal BulkheadPolicy( @@ -18,12 +17,14 @@ internal BulkheadPolicy( int maxQueueingActions, Action onBulkheadRejected) { - _maxQueueingActions = maxQueueingActions; + MaxQueueingActions = maxQueueingActions; _onBulkheadRejected = onBulkheadRejected; (_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions); } + private int MaxQueueingActions { get; } + /// [DebuggerStepThrough] protected override TResult Implementation(Func action, Context context, CancellationToken cancellationToken) @@ -50,7 +51,7 @@ protected override TResult Implementation(Func /// Gets the number of slots currently available for queuing actions for execution through the bulkhead. /// - public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions); + public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions); #pragma warning disable CA1063 /// @@ -76,7 +77,6 @@ public class BulkheadPolicy : Policy, IBulkheadPolicy { private readonly SemaphoreSlim _maxParallelizationSemaphore; private readonly SemaphoreSlim _maxQueuedActionsSemaphore; - private readonly int _maxQueueingActions; private readonly Action _onBulkheadRejected; internal BulkheadPolicy( @@ -84,12 +84,14 @@ internal BulkheadPolicy( int maxQueueingActions, Action onBulkheadRejected) { - _maxQueueingActions = maxQueueingActions; + MaxQueueingActions = maxQueueingActions; _onBulkheadRejected = onBulkheadRejected; (_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions); } + private int MaxQueueingActions { get; } + /// [DebuggerStepThrough] protected override TResult Implementation(Func action, Context context, CancellationToken cancellationToken) @@ -115,7 +117,7 @@ protected override TResult Implementation(Func /// Gets the number of slots currently available for queuing actions for execution through the bulkhead. /// - public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions); + public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions); #pragma warning disable CA1063 /// diff --git a/test/Polly.Specs/Polly.Specs.csproj b/test/Polly.Specs/Polly.Specs.csproj index 246fcbdaae6..8dae7243b65 100644 --- a/test/Polly.Specs/Polly.Specs.csproj +++ b/test/Polly.Specs/Polly.Specs.csproj @@ -1,6 +1,6 @@  - net8.0;net9.0 + net9.0;net8.0 $(TargetFrameworks);net481 enable Test