Skip to content

Commit

Permalink
Implement HedgingResilienceStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Apr 28, 2023
1 parent 38ae8fd commit ed306c4
Show file tree
Hide file tree
Showing 36 changed files with 2,638 additions and 43 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ updates:
- dependency-name: "Microsoft.Extensions.Logging"
- dependency-name: "System.Diagnostics.DiagnosticSource"
- dependency-name: "System.Threading.RateLimiting"
- dependency-name: "Microsoft.Bcl.AsyncInterfaces"
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PackageVersion Include="BenchmarkDotNet" Version="0.13.5" />
<PackageVersion Include="FluentAssertions" Version="6.10.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.1" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
Expand Down Expand Up @@ -34,4 +35,4 @@
<PackageVersion Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
</ItemGroup>
</Project>
</Project>
36 changes: 36 additions & 0 deletions src/Polly.Core.Tests/Hedging/Controller/HedgingControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Polly.Hedging;
using Polly.Hedging.Utils;

namespace Polly.Core.Tests.Hedging.Controller;

public class HedgingControllerTests
{
[Fact]
public async Task Pooling_Ok()
{
var handler = new HedgingHandler().SetHedging<int>(handler => handler.HedgingActionGenerator = args => null).CreateHandler();
var controller = new HedgingController(new HedgingTimeProvider(), handler!, 3);

var context1 = controller.GetContext(ResilienceContext.Get());
await PrepareAsync(context1);

var context2 = controller.GetContext(ResilienceContext.Get());
await PrepareAsync(context2);

controller.RentedContexts.Should().Be(2);
controller.RentedExecutions.Should().Be(2);

context1.Complete();
context2.Complete();

controller.RentedContexts.Should().Be(0);
controller.RentedExecutions.Should().Be(0);
}

private static async Task PrepareAsync(HedgingExecutionContext context)
{
await context.LoadExecutionAsync((_, _) => new ValueTask<int>(10), "state");
await context.TryWaitForCompletedExecutionAsync(HedgingStrategyOptions.InfiniteHedgingDelay);
context.Tasks[0].AcceptOutcome();
}
}
Loading

0 comments on commit ed306c4

Please sign in to comment.