Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consistent expression bodied member usage #1021

Merged
merged 1 commit into from
Jan 14, 2023
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
34 changes: 11 additions & 23 deletions src/Polly.Benchmarks/Bulkhead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,26 @@ public class Bulkhead
private static readonly AsyncPolicy AsyncPolicy = Policy.BulkheadAsync(2);

[Benchmark]
public void Bulkhead_Synchronous()
{
public void Bulkhead_Synchronous() =>
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public Task Bulkhead_Asynchronous()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());
}
public Task Bulkhead_Asynchronous() =>
AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());

[Benchmark]
public Task Bulkhead_Asynchronous_With_CancellationToken()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);
}
public Task Bulkhead_Asynchronous_With_CancellationToken() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);

[Benchmark]
public int Bulkhead_Synchronous_With_Result()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int Bulkhead_Synchronous_With_Result() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> Bulkhead_Asynchronous_With_Result()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
public Task<int> Bulkhead_Asynchronous_With_Result() =>
AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());

[Benchmark]
public Task<int> Bulkhead_Asynchronous_With_Result_With_CancellationToken()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
public Task<int> Bulkhead_Asynchronous_With_Result_With_CancellationToken() =>
AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
40 changes: 15 additions & 25 deletions src/Polly.Benchmarks/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,33 @@ public Task GlobalSetup()
}

[Benchmark]
public object Cache_Synchronous_Hit()
{
return SyncPolicyHit.Execute(_ => GetObject(), HitContext);
}
public object Cache_Synchronous_Hit() =>
SyncPolicyHit.Execute(_ => GetObject(), HitContext);

[Benchmark]
public Task<object> Cache_Asynchronous_Hit()
{
return AsyncPolicyHit.ExecuteAsync((_, token) => GetObjectAsync(token), HitContext, CancellationToken.None);
}
public Task<object> Cache_Asynchronous_Hit() =>
AsyncPolicyHit.ExecuteAsync((_, token) => GetObjectAsync(token), HitContext, CancellationToken.None);

[Benchmark]
public object Cache_Synchronous_Miss()
{
return SyncPolicyMiss.Execute(_ => GetObject(), MissContext);
}
public object Cache_Synchronous_Miss() =>
SyncPolicyMiss.Execute(_ => GetObject(), MissContext);

[Benchmark]
public Task<object> Cache_Asynchronous_Miss()
{
return AsyncPolicyMiss.ExecuteAsync((_, token) => GetObjectAsync(token), MissContext, CancellationToken.None);
}
public Task<object> Cache_Asynchronous_Miss() =>
AsyncPolicyMiss.ExecuteAsync((_, token) => GetObjectAsync(token), MissContext, CancellationToken.None);

private static object GetObject() => new object();
private static object GetObject() =>
new object();

private static Task<object> GetObjectAsync(CancellationToken cancellationToken) => Task.FromResult(new object());
private static Task<object> GetObjectAsync(CancellationToken cancellationToken) =>
Task.FromResult(new object());

private sealed class MemoryCacheProvider : ISyncCacheProvider, IAsyncCacheProvider
{
private readonly IMemoryCache _cache;

public MemoryCacheProvider(IMemoryCache memoryCache)
{
public MemoryCacheProvider(IMemoryCache memoryCache) =>
_cache = memoryCache;
}

public (bool, object?) TryGet(string key)
{
Expand Down Expand Up @@ -91,10 +83,8 @@ public void Put(string key, object value, Ttl ttl)
_cache.Set(key, value, options);
}

public Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
return Task.FromResult(TryGet(key));
}
public Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) =>
Task.FromResult(TryGet(key));

public Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
Expand Down
22 changes: 7 additions & 15 deletions src/Polly.Benchmarks/CircuitBreaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,18 @@ public class CircuitBreaker
private static readonly AsyncPolicy AsyncPolicy = Policy.Handle<InvalidOperationException>().CircuitBreakerAsync(2, TimeSpan.FromMinutes(1));

[Benchmark]
public void CircuitBreaker_Synchronous_Succeeds()
{
public void CircuitBreaker_Synchronous_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public Task CircuitBreaker_Asynchronous_Succeeds()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);
}
public Task CircuitBreaker_Asynchronous_Succeeds() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);

[Benchmark]
public int CircuitBreaker_Synchronous_With_Result_Succeeds()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int CircuitBreaker_Synchronous_With_Result_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> CircuitBreaker_Asynchronous_With_Result_Succeeds()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
public Task<int> CircuitBreaker_Asynchronous_With_Result_Succeeds() =>
AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
24 changes: 8 additions & 16 deletions src/Polly.Benchmarks/Fallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,18 @@ public class Fallback
private static readonly AsyncPolicy<int> AsyncPolicy = Policy<int>.Handle<InvalidOperationException>().FallbackAsync(0);

[Benchmark]
public int Fallback_Synchronous_Succeeds()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int Fallback_Synchronous_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> Fallback_Asynchronous_Succeeds()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
public Task<int> Fallback_Asynchronous_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());

[Benchmark]
public int Fallback_Synchronous_Throws()
{
return SyncPolicy.Execute(() => Workloads.FuncThrows<int, InvalidOperationException>());
}
public int Fallback_Synchronous_Throws() =>
SyncPolicy.Execute(() => Workloads.FuncThrows<int, InvalidOperationException>());

[Benchmark]
public Task<int> Fallback_Asynchronous_Throws()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.FuncThrowsAsync<int, InvalidOperationException>());
}
public Task<int> Fallback_Asynchronous_Throws() =>
AsyncPolicy.ExecuteAsync(() => Workloads.FuncThrowsAsync<int, InvalidOperationException>());
}
22 changes: 7 additions & 15 deletions src/Polly.Benchmarks/NoOp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,18 @@ public class NoOp
private static readonly AsyncPolicy AsyncPolicy = Policy.NoOpAsync();

[Benchmark]
public void NoOp_Synchronous()
{
public void NoOp_Synchronous() =>
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public Task NoOp_Asynchronous()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);
}
public Task NoOp_Asynchronous() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);

[Benchmark]
public int NoOp_Synchronous_With_Result()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int NoOp_Synchronous_With_Result() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> NoOp_Asynchronous_With_Result()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
public Task<int> NoOp_Asynchronous_With_Result() =>
AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
22 changes: 7 additions & 15 deletions src/Polly.Benchmarks/PolicyWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,18 @@ public class PolicyWrap
Policy.BulkheadAsync(2));

[Benchmark]
public void PolicyWrap_Synchronous()
{
public void PolicyWrap_Synchronous() =>
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public Task PolicyWrap_Asynchronous()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);
}
public Task PolicyWrap_Asynchronous() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);

[Benchmark]
public int PolicyWrap_Synchronous_With_Result()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int PolicyWrap_Synchronous_With_Result() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> PolicyWrap_Asynchronous_With_Result()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
public Task<int> PolicyWrap_Asynchronous_With_Result() =>
AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
22 changes: 7 additions & 15 deletions src/Polly.Benchmarks/RateLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,18 @@ public class RateLimit
private static readonly AsyncPolicy AsyncPolicy = Policy.RateLimitAsync(20, TimeSpan.FromSeconds(1), int.MaxValue);

[Benchmark]
public void RateLimit_Synchronous_Succeeds()
{
public void RateLimit_Synchronous_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public Task RateLimit_Asynchronous_Succeeds()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());
}
public Task RateLimit_Asynchronous_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());

[Benchmark]
public int RateLimit_Synchronous_With_Result_Succeeds()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int RateLimit_Synchronous_With_Result_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> RateLimit_Asynchronous_With_Result_Succeeds()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
public Task<int> RateLimit_Asynchronous_With_Result_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
34 changes: 11 additions & 23 deletions src/Polly.Benchmarks/Retry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,28 @@ public class Retry
private static readonly AsyncPolicy AsyncPolicy = Policy.Handle<InvalidOperationException>().RetryAsync();

[Benchmark]
public void Retry_Synchronous_Succeeds()
{
public void Retry_Synchronous_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public Task Retry_Asynchronous_Succeeds()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());
}
public Task Retry_Asynchronous_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());

[Benchmark]
public Task Retry_Asynchronous_Succeeds_With_CancellationToken()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);
}
public Task Retry_Asynchronous_Succeeds_With_CancellationToken() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);

[Benchmark]
public int Retry_Synchronous_With_Result_Succeeds()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int Retry_Synchronous_With_Result_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> Retry_Asynchronous_With_Result_Succeeds()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
public Task<int> Retry_Asynchronous_With_Result_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());

[Benchmark]
public Task<int> Retry_Asynchronous_With_Result_Succeeds_With_CancellationToken()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
public Task<int> Retry_Asynchronous_With_Result_Succeeds_With_CancellationToken() =>
AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);

[Benchmark]
public void Retry_Synchronous_Throws_Then_Succeeds()
Expand Down
40 changes: 13 additions & 27 deletions src/Polly.Benchmarks/Timeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,30 @@ public class Timeout
private static readonly AsyncPolicy AsyncPolicy = Policy.TimeoutAsync(TimeSpan.FromMilliseconds(1));

[Benchmark]
public void Timeout_Synchronous_Succeeds()
{
public void Timeout_Synchronous_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Action());
}

[Benchmark]
public Task Timeout_Asynchronous_Succeeds()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());
}
public Task Timeout_Asynchronous_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync());

[Benchmark]
public Task Timeout_Asynchronous_Succeeds_With_CancellationToken()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);
}
public Task Timeout_Asynchronous_Succeeds_With_CancellationToken() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);

[Benchmark]
public int Timeout_Synchronous_With_Result_Succeeds()
{
return SyncPolicy.Execute(() => Workloads.Func<int>());
}
public int Timeout_Synchronous_With_Result_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Func<int>());

[Benchmark]
public Task<int> Timeout_Asynchronous_With_Result_Succeeds()
{
return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
public Task<int> Timeout_Asynchronous_With_Result_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());

[Benchmark]
public Task<int> Timeout_Asynchronous_With_Result_Succeeds_With_CancellationToken()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
}
public Task<int> Timeout_Asynchronous_With_Result_Succeeds_With_CancellationToken() =>
AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);

[Benchmark]
public Task Timeout_Asynchronous_Times_Out_Optimistic()
{
return AsyncPolicy.ExecuteAsync(token => Workloads.ActionInfiniteAsync(token), CancellationToken.None);
}
public Task Timeout_Asynchronous_Times_Out_Optimistic() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionInfiniteAsync(token), CancellationToken.None);
}
Loading