Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed May 23, 2023
1 parent 6231fb3 commit dacf762
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Polly.Core.Benchmarks/CircuitBreakerOpenedBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Polly.Core.Benchmarks;

namespace Polly.Benchmarks;
namespace Polly.Core.Benchmarks;

public class CircuitBreakerOpenedBenchmark
{
Expand Down
19 changes: 16 additions & 3 deletions src/Polly.Core.Benchmarks/ResilienceStrategyBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ public class ResilienceStrategyBenchmark
private readonly ResilienceStrategy<string> _genericStrategy = NullResilienceStrategy<string>.Instance;

[Benchmark(Baseline = true)]
public async ValueTask ExecuteOutcomeAsync()
{
var context = ResilienceContext.Get();
await _strategy.ExecuteOutcomeAsync((_, _) => new ValueTask<Outcome<string>>(new Outcome<string>("dummy")), context, "state").ConfigureAwait(false);
ResilienceContext.Return(context);
}

[Benchmark]
public async ValueTask ExecuteAsync_ResilienceContextAndState()
{
var context = ResilienceContext.Get();
await _strategy.ExecuteAsync((_, _) => new ValueTask<Outcome<string>>(new Outcome<string>("dummy")), context, "state").ConfigureAwait(false);
await _strategy.ExecuteAsync((_, _) => new ValueTask<string>(new string("dummy")), context, "state").ConfigureAwait(false);
ResilienceContext.Return(context);
}

Expand All @@ -33,8 +41,13 @@ public async ValueTask ExecuteAsync_GenericStrategy_CancellationToken()

private class DummyResilienceStrategy : ResilienceStrategy
{
protected override ValueTask<TResult> ExecuteCoreAsync<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<TResult>> callback,
public ValueTask<Outcome<TResult>> ExecuteOutcomeAsync<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state) => ExecuteCoreAsync(callback, context, state);

protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state) => callback(context, state);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Polly.Core.Benchmarks/Utils/EmptyResilienceStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Polly.Strategy;

namespace Polly.Core.Benchmarks.Utils;

internal class EmptyResilienceStrategy : ResilienceStrategy
Expand Down

0 comments on commit dacf762

Please sign in to comment.