Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5.0.1
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@2016bd2012dba4e32de620c46fe006a3ac9f0602 # v5.0.1
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.8.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="MinVer" Version="6.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="Polly" Version="8.6.5" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
Expand Down
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>net9.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ProjectType>Benchmark</ProjectType>
<NoWarn>$(NoWarn);CA1822;IDE0060</NoWarn>
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
2 changes: 1 addition & 1 deletion test/Polly.Specs/Polly.Specs.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net481</TargetFrameworks>
<Nullable>enable</Nullable>
<ProjectType>Test</ProjectType>
Expand Down
Loading