Skip to content
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
with:
dotnet-version: |
8.0.x
9.0.x

- name: Setup .NET SDK
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
with:
dotnet-version: |
8.0.x
9.0.x

- name: Setup .NET SDK
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
Expand Down
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<Deterministic>true</Deterministic>
</PropertyGroup>
<!-- HACK Workaround for https://github.com/dotnet/sdk/issues/51265 -->
<PropertyGroup>
<RestoreEnablePackagePruning>false</RestoreEnablePackagePruning>
</PropertyGroup>
</Project>
9 changes: 8 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.15.0.120848" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="4.5.0" />
<PackageVersion Include="System.Text.Json" Version="9.0.8" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
Expand All @@ -58,4 +57,12 @@
<PackageVersion Update="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
<PackageVersion Update="System.Threading.RateLimiting" Version="9.0.0" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net10.0'))">
<PackageVersion Update="Microsoft.Bcl.TimeProvider" Version="10.0.0-rc.2.25502.107" />
<PackageVersion Update="Microsoft.Extensions.Logging" Version="10.0.0-rc.2.25502.107" />
<PackageVersion Update="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0-rc.2.25502.107" />
<PackageVersion Update="Microsoft.Extensions.Options" Version="10.0.0-rc.2.25502.107" />
<PackageVersion Update="System.Diagnostics.DiagnosticSource" Version="10.0.0-rc.2.25502.107" />
<PackageVersion Update="System.Threading.RateLimiting" Version="10.0.0-rc.2.25502.107" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion bench/Polly.Benchmarks/Polly.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ProjectType>Benchmark</ProjectType>
<NoWarn>$(NoWarn);CA1822;IDE0060</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion bench/Polly.Core.Benchmarks/Polly.Core.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<RootNamespace>Polly</RootNamespace>
<ImplicitUsings>true</ImplicitUsings>
<ProjectType>Benchmark</ProjectType>
Expand Down
2 changes: 1 addition & 1 deletion bench/benchmarks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ if ($Interactive -ne $true) {

$project = Join-Path "Polly.Core.Benchmarks" "Polly.Core.Benchmarks.csproj"

dotnet run --configuration $Configuration --framework net9.0 --project $project $additionalArgs
dotnet run --configuration $Configuration --framework net10.0 --project $project $additionalArgs

exit $LASTEXITCODE
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ https://cakebuild.net
#>

Param(
[string]$Script = "build.cake",
[string]$Script = "cake.cs",
[string]$Target = "Default",
[ValidateSet("Default", "MutationCore", "MutationLegacy")]
[string]$Configuration = "Release",
Expand Down Expand Up @@ -82,6 +82,6 @@ if ($WhatIf.IsPresent) {
# Start Cake
Write-Output "Running build script..."

& dotnet cake $Script "--target=$Target" "--configuration=$Configuration" "--verbosity=$Verbosity" $additionalArgs
& dotnet $Script -- "--target=$Target" "--configuration=$Configuration" "--verbosity=$Verbosity" $additionalArgs

exit $LASTEXITCODE
18 changes: 6 additions & 12 deletions build.cake → cake.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#:sdk Cake.Sdk
#:package Cake.FileHelpers
#:package Newtonsoft.Json
#:property ProjectType=Test
#:property SignAssembly=false

///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////

var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");

//////////////////////////////////////////////////////////////////////
// EXTERNAL NUGET LIBRARIES
//////////////////////////////////////////////////////////////////////

#addin nuget:?package=Cake.FileHelpers&version=7.0.0
#addin nuget:?package=Newtonsoft.Json&version=13.0.3

///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -285,11 +284,6 @@
// HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////

string ToolsExePath(string exeFileName) {
var exePath = System.IO.Directory.GetFiles("./tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault();
return exePath;
}

string PatchStrykerConfig(string path, Action<Newtonsoft.Json.Linq.JObject> patch)
{
var json = System.IO.File.ReadAllText(path);
Expand Down
3 changes: 2 additions & 1 deletion eng/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"concurrency": 4,
"configuration": "Debug",
"target-framework": "net8.0",
"language-version": "Preview",
"target-framework": "net10.0",
"thresholds": {
"high": 100,
"low": 100
Expand Down
5 changes: 4 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"sdk": {
"version": "9.0.306",
"version": "10.0.100-rc.2.25502.107",
"allowPrerelease": false,
"rollForward": "latestMajor"
},
"msbuild-sdks": {
"Cake.Sdk": "5.0.25257.82-beta"
}
}
3 changes: 1 addition & 2 deletions samples/Chaos/Chaos.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>Chaos</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Polly.Core" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion samples/DependencyInjection/DependencyInjection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Extensibility/Extensibility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/GenericPipelines/GenericPipelines.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Intro/Intro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Retries/Retries.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 8 additions & 6 deletions src/Polly/Bulkhead/AsyncBulkheadPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ public class AsyncBulkheadPolicy : AsyncPolicy, IBulkheadPolicy
{
private readonly SemaphoreSlim _maxParallelizationSemaphore;
private readonly SemaphoreSlim _maxQueuedActionsSemaphore;
private readonly int _maxQueueingActions;
private readonly Func<Context, Task> _onBulkheadRejectedAsync;

internal AsyncBulkheadPolicy(
int maxParallelization,
int maxQueueingActions,
Func<Context, Task> onBulkheadRejectedAsync)
{
_maxQueueingActions = maxQueueingActions;
MaxQueueingActions = maxQueueingActions;
_onBulkheadRejectedAsync = onBulkheadRejectedAsync;

(_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions);
}

private int MaxQueueingActions { get; }

/// <summary>
/// Gets the number of slots currently available for executing actions through the bulkhead.
/// </summary>
Expand All @@ -32,7 +33,7 @@ internal AsyncBulkheadPolicy(
/// <summary>
/// Gets the number of slots currently available for queuing actions for execution through the bulkhead.
/// </summary>
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions);
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions);

/// <inheritdoc/>
[DebuggerStepThrough]
Expand Down Expand Up @@ -78,20 +79,21 @@ public class AsyncBulkheadPolicy<TResult> : AsyncPolicy<TResult>, IBulkheadPolic
{
private readonly SemaphoreSlim _maxParallelizationSemaphore;
private readonly SemaphoreSlim _maxQueuedActionsSemaphore;
private readonly int _maxQueueingActions;
private readonly Func<Context, Task> _onBulkheadRejectedAsync;

internal AsyncBulkheadPolicy(
int maxParallelization,
int maxQueueingActions,
Func<Context, Task> onBulkheadRejectedAsync)
{
_maxQueueingActions = maxQueueingActions;
MaxQueueingActions = maxQueueingActions;
_onBulkheadRejectedAsync = onBulkheadRejectedAsync;

(_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions);
}

private int MaxQueueingActions { get; }

/// <inheritdoc/>
[DebuggerStepThrough]
protected override Task<TResult> ImplementationAsync(
Expand Down Expand Up @@ -123,7 +125,7 @@ protected override Task<TResult> ImplementationAsync(
/// <summary>
/// Gets the number of slots currently available for queuing actions for execution through the bulkhead.
/// </summary>
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions);
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions);

#pragma warning disable CA1063
/// <inheritdoc/>
Expand Down
14 changes: 8 additions & 6 deletions src/Polly/Bulkhead/BulkheadPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ public class BulkheadPolicy : Policy, IBulkheadPolicy
{
private readonly SemaphoreSlim _maxParallelizationSemaphore;
private readonly SemaphoreSlim _maxQueuedActionsSemaphore;
private readonly int _maxQueueingActions;
private readonly Action<Context> _onBulkheadRejected;

internal BulkheadPolicy(
int maxParallelization,
int maxQueueingActions,
Action<Context> onBulkheadRejected)
{
_maxQueueingActions = maxQueueingActions;
MaxQueueingActions = maxQueueingActions;
_onBulkheadRejected = onBulkheadRejected;

(_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions);
}

private int MaxQueueingActions { get; }

/// <inheritdoc/>
[DebuggerStepThrough]
protected override TResult Implementation<TResult>(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
Expand All @@ -50,7 +51,7 @@ protected override TResult Implementation<TResult>(Func<Context, CancellationTok
/// <summary>
/// Gets the number of slots currently available for queuing actions for execution through the bulkhead.
/// </summary>
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions);
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions);

#pragma warning disable CA1063
/// <summary>
Expand All @@ -76,20 +77,21 @@ public class BulkheadPolicy<TResult> : Policy<TResult>, IBulkheadPolicy<TResult>
{
private readonly SemaphoreSlim _maxParallelizationSemaphore;
private readonly SemaphoreSlim _maxQueuedActionsSemaphore;
private readonly int _maxQueueingActions;
private readonly Action<Context> _onBulkheadRejected;

internal BulkheadPolicy(
int maxParallelization,
int maxQueueingActions,
Action<Context> onBulkheadRejected)
{
_maxQueueingActions = maxQueueingActions;
MaxQueueingActions = maxQueueingActions;
_onBulkheadRejected = onBulkheadRejected;

(_maxParallelizationSemaphore, _maxQueuedActionsSemaphore) = BulkheadSemaphoreFactory.CreateBulkheadSemaphores(maxParallelization, maxQueueingActions);
}

private int MaxQueueingActions { get; }

/// <inheritdoc/>
[DebuggerStepThrough]
protected override TResult Implementation(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
Expand All @@ -115,7 +117,7 @@ protected override TResult Implementation(Func<Context, CancellationToken, TResu
/// <summary>
/// Gets the number of slots currently available for queuing actions for execution through the bulkhead.
/// </summary>
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions);
public int QueueAvailableCount => Math.Min(_maxQueuedActionsSemaphore.CurrentCount, MaxQueueingActions);

#pragma warning disable CA1063
/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions src/Polly/Context.Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public partial class Context : IDictionary<string, object>, IDictionary, IReadOn
// For an individual execution through a policy or policywrap, it is expected that all execution steps (for example executing the user delegate, invoking policy-activity delegates such as onRetry, onBreak, onTimeout etc) execute sequentially.
// Therefore, this class is intentionally not constructed to be safe for concurrent access from multiple threads.

private Dictionary<string, object> _wrappedDictionary;

private Dictionary<string, object> WrappedDictionary => _wrappedDictionary ?? (_wrappedDictionary = []);
private Dictionary<string, object> WrappedDictionary
{
get => field ??= [];
set;
}

/// <summary>
/// Initializes a new instance of the <see cref="Context"/> class, with the specified <paramref name="operationKey" /> and the supplied <paramref name="contextData"/>.
Expand All @@ -32,7 +34,7 @@ internal Context(IDictionary<string, object> contextData)
throw new ArgumentNullException(nameof(contextData));
}

_wrappedDictionary = new Dictionary<string, object>(contextData);
WrappedDictionary = new Dictionary<string, object>(contextData);
}

#region IDictionary<string,object> implementation
Expand Down
3 changes: 1 addition & 2 deletions src/Snippets/Snippets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ProjectType>Library</ProjectType>
Expand All @@ -29,7 +29,6 @@
<PackageReference Include="NSubstitute" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="RestSharp" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="xunit" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion test/Polly.AotTest/Polly.AotTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PublishAot>true</PublishAot>
<SKIP_POLLY_ANALYZERS>true</SKIP_POLLY_ANALYZERS>
<SelfContained>true</SelfContained>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Polly.Core\Polly.Core.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion test/Polly.Core.Tests/Polly.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net481</TargetFrameworks>
<TestTfmsInParallel Condition="$([MSBuild]::IsOSPlatform('Windows'))">false</TestTfmsInParallel>
<ProjectType>Test</ProjectType>
Expand Down
Loading
Loading