Skip to content

Commit

Permalink
Merge branch 'main' into dotnet-8
Browse files Browse the repository at this point in the history
  • Loading branch information
martincostello authored Aug 11, 2023
2 parents 75ea78e + da345d0 commit 727f401
Show file tree
Hide file tree
Showing 71 changed files with 322 additions and 221 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ jobs:
restore-keys: ${{ runner.os }}-nuget-

- name: Initialize CodeQL
uses: github/codeql-action/init@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2
uses: github/codeql-action/init@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2
uses: github/codeql-action/autobuild@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2
uses: github/codeql-action/analyze@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3
with:
category: "/language:${{ matrix.language }}"
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Review dependencies
uses: actions/dependency-review-action@1360a344ccb0ab6e9475edef90ad2f46bf8003b1 # v3.0.6
uses: actions/dependency-review-action@7d90b4f05fea31dde1c4a1fb3fa787e197ea93ab # v3.0.7
2 changes: 1 addition & 1 deletion .github/workflows/ossf-scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ jobs:
retention-days: 5

- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2
uses: github/codeql-action/upload-sarif@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3
with:
sarif_file: results.sarif
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.6" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.7" />
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.2" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
Expand All @@ -21,7 +21,7 @@
<PackageVersion Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.0.0-preview.7.23407.5" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="NSubstitute" Version="5.0.0" />
Expand All @@ -30,7 +30,7 @@
<PackageVersion Include="Polly.Extensions" Version="$(PollyVersion)" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageVersion Include="ReportGenerator" Version="5.1.23" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.6.0.74858" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.7.0.75501" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.507" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="4.5.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="$(MicrosoftExtensionsVersion)" />
Expand Down
2 changes: 1 addition & 1 deletion bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private ResilienceStrategy Build(CompositeStrategyBuilder builder)
return builder.Build();
}

private class TelemetryEventStrategy : ResilienceStrategy
private class TelemetryEventStrategy : NonReactiveResilienceStrategy
{
private readonly ResilienceStrategyTelemetry _telemetry;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Polly.Core.Benchmarks.Utils;

internal class EmptyResilienceStrategy : ResilienceStrategy
internal class EmptyResilienceStrategy : NonReactiveResilienceStrategy
{
protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
Expand Down
4 changes: 2 additions & 2 deletions bench/Polly.Core.Benchmarks/Utils/Helper.CircuitBreaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static object CreateOpenedCircuitBreaker(PollyVersion version, bool handl

if (handleOutcome)
{
builder.AddStrategy(new OutcomeHandlingStrategy());
builder.AddStrategy(_ => new OutcomeHandlingStrategy(), new EmptyResilienceOptions());
}

var strategy = builder.AddCircuitBreaker(options).Build();
Expand Down Expand Up @@ -64,7 +64,7 @@ public static object CreateCircuitBreaker(PollyVersion technology)
};
}

private class OutcomeHandlingStrategy : ResilienceStrategy
private class OutcomeHandlingStrategy : NonReactiveResilienceStrategy
{
protected override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static partial class Helper
{
for (var i = 0; i < count; i++)
{
builder.AddStrategy(new EmptyResilienceStrategy());
builder.AddStrategy(_ => new EmptyResilienceStrategy(), new EmptyResilienceOptions());
}
}),
_ => throw new NotSupportedException()
Expand Down
2 changes: 2 additions & 0 deletions src/Polly.Core/CircuitBreaker/CircuitBreakerConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Polly.CircuitBreaker;

internal static class CircuitBreakerConstants
{
public const string DefaultName = "CircuitBreaker";

public const string OnCircuitClosed = "OnCircuitClosed";

public const string OnHalfOpenEvent = "OnCircuitHalfOpened";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ namespace Polly.CircuitBreaker;
/// </remarks>
public class CircuitBreakerStrategyOptions<TResult> : ResilienceStrategyOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="CircuitBreakerStrategyOptions{TResult}"/> class.
/// </summary>
public CircuitBreakerStrategyOptions() => Name = CircuitBreakerConstants.DefaultName;

/// <summary>
/// Gets or sets the failure-to-success ratio at which the circuit will break.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public ValueTask CloseCircuitAsync(ResilienceContext context)
exception = _circuitState switch
{
CircuitState.Open => _breakingException,
CircuitState.HalfOpen when isHalfOpen is false => _breakingException,
CircuitState.HalfOpen when !isHalfOpen => _breakingException,
CircuitState.Isolated => new IsolatedCircuitException(),
_ => null
};
Expand Down
7 changes: 4 additions & 3 deletions src/Polly.Core/CompositeStrategyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, ResilienceSt
Guard.NotNull(builder);
Guard.NotNull(strategy);

return builder.AddStrategy(_ => strategy, EmptyOptions.Instance);
builder.AddStrategyCore(_ => strategy, EmptyOptions.Instance);
return builder;
}

/// <summary>
Expand Down Expand Up @@ -59,14 +60,14 @@ public static CompositeStrategyBuilder<TResult> AddStrategy<TResult>(this Compos
/// <exception cref="InvalidOperationException">Thrown when this builder was already used to create a strategy. The builder cannot be modified after it has been used.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> is invalid.</exception>
[RequiresUnreferencedCode(Constants.OptionsValidation)]
public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, Func<StrategyBuilderContext, ResilienceStrategy> factory, ResilienceStrategyOptions options)
public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, Func<StrategyBuilderContext, NonReactiveResilienceStrategy> factory, ResilienceStrategyOptions options)
where TBuilder : CompositeStrategyBuilderBase
{
Guard.NotNull(builder);
Guard.NotNull(factory);
Guard.NotNull(options);

builder.AddStrategyCore(factory, options);
builder.AddStrategyCore(context => new NonReactiveResilienceStrategyBridge(factory(context)), options);
return builder;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Polly.Core/Fallback/FallbackConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Polly.Fallback;

internal static class FallbackConstants
{
public const string DefaultName = "Fallback";

public const string OnFallback = "OnFallback";
}

5 changes: 5 additions & 0 deletions src/Polly.Core/Fallback/FallbackStrategyOptions.TResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Polly.Fallback;
/// <typeparam name="TResult">The result type.</typeparam>
public class FallbackStrategyOptions<TResult> : ResilienceStrategyOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="FallbackStrategyOptions{TResult}"/> class.
/// </summary>
public FallbackStrategyOptions() => Name = FallbackConstants.DefaultName;

/// <summary>
/// Gets or sets the outcome predicate for determining whether a fallback should be executed.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Polly.Core/Hedging/HedgingConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Polly.Hedging;

internal static class HedgingConstants
{
public const string DefaultName = "Hedging";

public const string OnHedgingEventName = "OnHedging";

public const int DefaultMaxHedgedAttempts = 2;
Expand Down
5 changes: 5 additions & 0 deletions src/Polly.Core/Hedging/HedgingStrategyOptions.TResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Polly.Hedging;
/// <typeparam name="TResult">The type of result these hedging options handle.</typeparam>
public class HedgingStrategyOptions<TResult> : ResilienceStrategyOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="HedgingStrategyOptions{TResult}"/> class.
/// </summary>
public HedgingStrategyOptions() => Name = HedgingConstants.DefaultName;

/// <summary>
/// Gets or sets the minimal time of waiting before spawning a new hedged call.
/// </summary>
Expand Down
36 changes: 36 additions & 0 deletions src/Polly.Core/NonReactiveResilienceStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Polly;

/// <summary>
/// Base class for all non-reactive resilience strategies.
/// </summary>
public abstract class NonReactiveResilienceStrategy
{
/// <summary>
/// An implementation of a non-reactive resilience strategy that executes the specified <paramref name="callback"/>.
/// </summary>
/// <typeparam name="TResult">The type of result returned by the callback.</typeparam>
/// <typeparam name="TState">The type of state associated with the callback.</typeparam>
/// <param name="callback">The user-provided callback.</param>
/// <param name="context">The context associated with the callback.</param>
/// <param name="state">The state associated with the callback.</param>
/// <returns>
/// An instance of a pending <see cref="ValueTask"/> for asynchronous executions or a completed <see cref="ValueTask"/> task for synchronous executions.
/// </returns>
/// <remarks>
/// <strong>This method is called for both synchronous and asynchronous execution flows.</strong>
/// <para>
/// You can use <see cref="ResilienceContext.IsSynchronous"/> to determine whether <paramref name="callback"/> is synchronous or asynchronous.
/// This is useful when the custom strategy behaves differently in each execution flow. In general, for most strategies, the implementation
/// is the same for both execution flows.
/// See <seealso href="https://github.com/App-vNext/Polly/blob/main/src/Polly.Core/README.md#about-synchronous-and-asynchronous-executions"/> for more details.
/// </para>
/// <para>
/// The provided callback never throws an exception. Instead, the exception is captured and converted to an <see cref="Outcome{TResult}"/>.
/// Similarly, do not throw exceptions from your strategy implementation. Instead, return an exception instance as <see cref="Outcome{TResult}"/>.
/// </para>
/// </remarks>
protected internal abstract ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state);
}
2 changes: 1 addition & 1 deletion src/Polly.Core/NullResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private NullResilienceStrategy()
}

/// <inheritdoc/>
protected internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
9 changes: 5 additions & 4 deletions src/Polly.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
abstract Polly.ReactiveResilienceStrategy<TResult>.ExecuteCore<TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>
abstract Polly.NonReactiveResilienceStrategy.ExecuteCore<TResult, TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>
abstract Polly.ReactiveResilienceStrategy<TResult>.ExecuteCore<TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy(TKey key, out Polly.ResilienceStrategy? strategy) -> bool
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy<TResult>(TKey key, out Polly.ResilienceStrategy<TResult>? strategy) -> bool
abstract Polly.ResilienceContextPool.Get(string? operationKey, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Polly.ResilienceContext!
abstract Polly.ResilienceContextPool.Return(Polly.ResilienceContext! context) -> void
abstract Polly.ResilienceStrategy.ExecuteCore<TResult, TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>
override Polly.Outcome<TResult>.ToString() -> string!
override Polly.Registry.ResilienceStrategyRegistry<TKey>.TryGetStrategy(TKey key, out Polly.ResilienceStrategy? strategy) -> bool
override Polly.Registry.ResilienceStrategyRegistry<TKey>.TryGetStrategy<TResult>(TKey key, out Polly.ResilienceStrategy<TResult>? strategy) -> bool
Expand Down Expand Up @@ -149,6 +149,8 @@ Polly.Hedging.OnHedgingArguments.HasOutcome.get -> bool
Polly.Hedging.OnHedgingArguments.OnHedgingArguments(int attemptNumber, bool hasOutcome, System.TimeSpan executionTime) -> void
Polly.HedgingCompositeStrategyBuilderExtensions
Polly.LegacySupport
Polly.NonReactiveResilienceStrategy
Polly.NonReactiveResilienceStrategy.NonReactiveResilienceStrategy() -> void
Polly.NullResilienceStrategy
Polly.NullResilienceStrategy<TResult>
Polly.Outcome
Expand Down Expand Up @@ -264,7 +266,6 @@ Polly.ResilienceStrategy.ExecuteAsync<TResult>(System.Func<System.Threading.Canc
Polly.ResilienceStrategy.ExecuteAsync<TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask
Polly.ResilienceStrategy.ExecuteAsync<TState>(System.Func<TState, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask>! callback, TState state, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
Polly.ResilienceStrategy.ExecuteOutcomeAsync<TResult, TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>
Polly.ResilienceStrategy.ResilienceStrategy() -> void
Polly.ResilienceStrategy<T>
Polly.ResilienceStrategy<T>.Execute<TResult, TState>(System.Func<Polly.ResilienceContext!, TState, TResult>! callback, Polly.ResilienceContext! context, TState state) -> TResult
Polly.ResilienceStrategy<T>.Execute<TResult, TState>(System.Func<TState, System.Threading.CancellationToken, TResult>! callback, TState state, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> TResult
Expand Down Expand Up @@ -392,7 +393,7 @@ static Polly.CircuitBreakerCompositeStrategyBuilderExtensions.AddCircuitBreaker(
static Polly.CircuitBreakerCompositeStrategyBuilderExtensions.AddCircuitBreaker<TResult>(this Polly.CompositeStrategyBuilder<TResult>! builder, Polly.CircuitBreaker.CircuitBreakerStrategyOptions<TResult>! options) -> Polly.CompositeStrategyBuilder<TResult>!
static Polly.CompositeStrategyBuilderExtensions.AddStrategy(this Polly.CompositeStrategyBuilder! builder, System.Func<Polly.StrategyBuilderContext!, Polly.ReactiveResilienceStrategy<object!>!>! factory, Polly.ResilienceStrategyOptions! options) -> Polly.CompositeStrategyBuilder!
static Polly.CompositeStrategyBuilderExtensions.AddStrategy<TBuilder>(this TBuilder! builder, Polly.ResilienceStrategy! strategy) -> TBuilder!
static Polly.CompositeStrategyBuilderExtensions.AddStrategy<TBuilder>(this TBuilder! builder, System.Func<Polly.StrategyBuilderContext!, Polly.ResilienceStrategy!>! factory, Polly.ResilienceStrategyOptions! options) -> TBuilder!
static Polly.CompositeStrategyBuilderExtensions.AddStrategy<TBuilder>(this TBuilder! builder, System.Func<Polly.StrategyBuilderContext!, Polly.NonReactiveResilienceStrategy!>! factory, Polly.ResilienceStrategyOptions! options) -> TBuilder!
static Polly.CompositeStrategyBuilderExtensions.AddStrategy<TResult>(this Polly.CompositeStrategyBuilder<TResult>! builder, Polly.ResilienceStrategy<TResult>! strategy) -> Polly.CompositeStrategyBuilder<TResult>!
static Polly.CompositeStrategyBuilderExtensions.AddStrategy<TResult>(this Polly.CompositeStrategyBuilder<TResult>! builder, System.Func<Polly.StrategyBuilderContext!, Polly.ReactiveResilienceStrategy<TResult>!>! factory, Polly.ResilienceStrategyOptions! options) -> Polly.CompositeStrategyBuilder<TResult>!
static Polly.FallbackCompositeStrategyBuilderExtensions.AddFallback<TResult>(this Polly.CompositeStrategyBuilder<TResult>! builder, Polly.Fallback.FallbackStrategyOptions<TResult>! options) -> Polly.CompositeStrategyBuilder<TResult>!
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/ReactiveResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public abstract class ReactiveResilienceStrategy<TResult>
{
/// <summary>
/// An implementation of resilience strategy that executes the specified <paramref name="callback"/>.
/// An implementation of a reactive resilience strategy that executes the specified <paramref name="callback"/>.
/// </summary>
/// <typeparam name="TState">The type of state associated with the callback.</typeparam>
/// <param name="callback">The user-provided callback.</param>
Expand Down
Loading

0 comments on commit 727f401

Please sign in to comment.