Skip to content

Commit

Permalink
Fix SA1111/SA1513/SA1121/SA1110 (#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
baranyaimate authored Jan 30, 2024
1 parent e5e1a2a commit 47b2d24
Show file tree
Hide file tree
Showing 48 changed files with 281 additions and 459 deletions.
3 changes: 1 addition & 2 deletions src/Polly/AsyncPolicy.GenericImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ protected abstract Task<TResult> ImplementationAsync(
Func<Context, CancellationToken, Task<TResult>> action,
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext
);
bool continueOnCapturedContext);
}
3 changes: 1 addition & 2 deletions src/Polly/AsyncPolicy.NonGenericImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ protected abstract Task<TResult> ImplementationAsync<TResult>(
Func<Context, CancellationToken, Task<TResult>> action,
Context context,
CancellationToken cancellationToken,
bool continueOnCapturedContext
);
bool continueOnCapturedContext);
}
1 change: 1 addition & 0 deletions src/Polly/Bulkhead/AsyncBulkheadEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
await onBulkheadRejectedAsync(context).ConfigureAwait(continueOnCapturedContext);
throw new BulkheadRejectedException();
}

try
{
await maxParallelizationSemaphore.WaitAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext);
Expand Down
3 changes: 1 addition & 2 deletions src/Polly/Bulkhead/AsyncBulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public static AsyncBulkheadPolicy BulkheadAsync(
return new AsyncBulkheadPolicy(
maxParallelization,
maxQueuingActions,
onBulkheadRejectedAsync
);
onBulkheadRejectedAsync);
}
}
3 changes: 1 addition & 2 deletions src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static AsyncBulkheadPolicy<TResult> BulkheadAsync<TResult>(int maxParalle
return new AsyncBulkheadPolicy<TResult>(
maxParallelization,
maxQueuingActions,
onBulkheadRejectedAsync
);
onBulkheadRejectedAsync);
}
}
3 changes: 1 addition & 2 deletions src/Polly/Bulkhead/BulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi
return new BulkheadPolicy(
maxParallelization,
maxQueuingActions,
onBulkheadRejected
);
onBulkheadRejected);
}
}
3 changes: 1 addition & 2 deletions src/Polly/Bulkhead/BulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization,
return new BulkheadPolicy<TResult>(
maxParallelization,
maxQueuingActions,
onBulkheadRejected
);
onBulkheadRejected);
}
}
1 change: 1 addition & 0 deletions src/Polly/Caching/AsyncCacheEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
valueFromCache = default;
onCacheGetError?.Invoke(context, cacheKey, ex);
}

if (cacheHit)
{
onCacheGet(context, cacheKey);
Expand Down
6 changes: 2 additions & 4 deletions src/Polly/Caching/AsyncSerializingCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cance
_serializer.Serialize(value),
ttl,
cancellationToken,
continueOnCapturedContext
);
continueOnCapturedContext);
}

/// <summary>
Expand Down Expand Up @@ -114,6 +113,5 @@ public Task PutAsync(string key, TResult? value, Ttl ttl, CancellationToken canc
_serializer.Serialize(value),
ttl,
cancellationToken,
continueOnCapturedContext
);
continueOnCapturedContext);
}
1 change: 1 addition & 0 deletions src/Polly/Caching/CacheEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal static TResult Implementation<TResult>(
valueFromCache = default;
onCacheGetError?.Invoke(context, cacheKey, ex);
}

if (cacheHit)
{
onCacheGet(context, cacheKey);
Expand Down
18 changes: 6 additions & 12 deletions src/Polly/CircuitBreaker/AdvancedCircuitBreakerSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
doNothingOnBreak,
doNothingOnReset
);
doNothingOnReset);
}

/// <summary>
Expand Down Expand Up @@ -72,8 +71,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
(exception, timespan, _) => onBreak(exception, timespan),
_ => onReset()
);
_ => onReset());

/// <summary>
/// <para>The circuit will break if, within any timeslice of duration <paramref name="samplingDuration"/>, the proportion of actions resulting in a handled exception exceeds <paramref name="failureThreshold"/>, provided also that the number of actions through the circuit in the timeslice is at least <paramref name="minimumThroughput" />. </para>
Expand Down Expand Up @@ -108,8 +106,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol
durationOfBreak,
onBreak,
onReset,
doNothingOnHalfOpen
);
doNothingOnHalfOpen);
}

/// <summary>
Expand Down Expand Up @@ -146,8 +143,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol
durationOfBreak,
(exception, timespan, _) => onBreak(exception, timespan),
_ => onReset(),
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="Policy" /> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -184,8 +180,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol
durationOfBreak,
(exception, _, timespan, context) => onBreak(exception, timespan, context),
onReset,
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="Policy" /> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -240,7 +235,6 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol
onHalfOpen);
return new CircuitBreakerPolicy(
policyBuilder,
breakerController
);
breakerController);
}
}
19 changes: 7 additions & 12 deletions src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public static CircuitBreakerPolicy<TResult> AdvancedCircuitBreaker<TResult>(this
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
doNothingOnBreak,
doNothingOnReset
);
doNothingOnReset);
}

/// <summary>
Expand Down Expand Up @@ -72,8 +71,7 @@ public static CircuitBreakerPolicy<TResult> AdvancedCircuitBreaker<TResult>(this
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
(outcome, timespan, _) => onBreak(outcome, timespan),
_ => onReset()
);
_ => onReset());

/// <summary>
/// <para>The circuit will break if, within any timeslice of duration <paramref name="samplingDuration"/>, the proportion of actions resulting in a handled exception or result exceeds <paramref name="failureThreshold"/>, provided also that the number of actions through the circuit in the timeslice is at least <paramref name="minimumThroughput" />. </para>
Expand Down Expand Up @@ -108,8 +106,7 @@ public static CircuitBreakerPolicy<TResult> AdvancedCircuitBreaker<TResult>(this
durationOfBreak,
onBreak,
onReset,
doNothingOnHalfOpen
);
doNothingOnHalfOpen);
}

/// <summary>
Expand Down Expand Up @@ -146,8 +143,7 @@ public static CircuitBreakerPolicy<TResult> AdvancedCircuitBreaker<TResult>(this
durationOfBreak,
(outcome, timespan, _) => onBreak(outcome, timespan),
_ => onReset(),
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="Policy{TResult}" /> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -185,8 +181,7 @@ public static CircuitBreakerPolicy<TResult> AdvancedCircuitBreaker<TResult>(this
durationOfBreak,
(outcome, _, timespan, context) => onBreak(outcome, timespan, context),
onReset,
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="Policy{TResult}" /> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -240,9 +235,9 @@ public static CircuitBreakerPolicy<TResult> AdvancedCircuitBreaker<TResult>(this
onBreak,
onReset,
onHalfOpen);

return new CircuitBreakerPolicy<TResult>(
policyBuilder,
breakerController
);
breakerController);
}
}
4 changes: 2 additions & 2 deletions src/Polly/CircuitBreaker/AdvancedCircuitController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public AdvancedCircuitController(
TimeSpan durationOfBreak,
Action<DelegateResult<TResult>, CircuitState, TimeSpan, Context> onBreak,
Action<Context> onReset,
Action onHalfOpen
)
Action onHalfOpen)
: base(durationOfBreak, onBreak, onReset, onHalfOpen)
{
_metrics = samplingDuration.Ticks < ResolutionOfCircuitTimer * NumberOfWindows
Expand Down Expand Up @@ -85,6 +84,7 @@ public override void OnActionFailure(DelegateResult<TResult> outcome, Context co
{
Break_NeedsLock(context);
}

break;

case CircuitState.Open:
Expand Down
19 changes: 7 additions & 12 deletions src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
doNothingOnBreak,
doNothingOnReset
);
doNothingOnReset);
}

/// <summary>
Expand Down Expand Up @@ -74,8 +73,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
(exception, timespan, _) => onBreak(exception, timespan),
_ => onReset()
);
_ => onReset());

/// <summary>
/// <para> Builds a <see cref="AsyncPolicy"/> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -112,8 +110,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB
durationOfBreak,
onBreak,
onReset,
doNothingOnHalfOpen
);
doNothingOnHalfOpen);
}

/// <summary>
Expand Down Expand Up @@ -150,8 +147,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB
durationOfBreak,
(exception, timespan, _) => onBreak(exception, timespan),
_ => onReset(),
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="AsyncPolicy"/> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -188,8 +184,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB
durationOfBreak,
(exception, _, timespan, context) => onBreak(exception, timespan, context),
onReset,
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="AsyncPolicy"/> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -242,9 +237,9 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB
(outcome, state, timespan, context) => onBreak(outcome.Exception, state, timespan, context),
onReset,
onHalfOpen);

return new AsyncCircuitBreakerPolicy(
policyBuilder,
breakerController
);
breakerController);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public static AsyncCircuitBreakerPolicy<TResult> AdvancedCircuitBreakerAsync<TRe
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
doNothingOnBreak,
doNothingOnReset
);
doNothingOnReset);
}

/// <summary>
Expand Down Expand Up @@ -73,8 +72,7 @@ public static AsyncCircuitBreakerPolicy<TResult> AdvancedCircuitBreakerAsync<TRe
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
(outcome, timespan, _) => onBreak(outcome, timespan),
_ => onReset()
);
_ => onReset());

/// <summary>
/// <para> Builds a <see cref="AsyncPolicy{TResult}"/> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -106,13 +104,13 @@ public static AsyncCircuitBreakerPolicy<TResult> AdvancedCircuitBreakerAsync<TRe
public static AsyncCircuitBreakerPolicy<TResult> AdvancedCircuitBreakerAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, double failureThreshold, TimeSpan samplingDuration, int minimumThroughput, TimeSpan durationOfBreak, Action<DelegateResult<TResult>, TimeSpan, Context> onBreak, Action<Context> onReset)
{
Action doNothingOnHalfOpen = () => { };

return policyBuilder.AdvancedCircuitBreakerAsync(
failureThreshold, samplingDuration, minimumThroughput,
durationOfBreak,
onBreak,
onReset,
doNothingOnHalfOpen
);
doNothingOnHalfOpen);
}

/// <summary>
Expand Down Expand Up @@ -149,8 +147,7 @@ public static AsyncCircuitBreakerPolicy<TResult> AdvancedCircuitBreakerAsync<TRe
durationOfBreak,
(outcome, timespan, _) => onBreak(outcome, timespan),
_ => onReset(),
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="AsyncPolicy{TResult}"/> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -187,8 +184,7 @@ public static AsyncCircuitBreakerPolicy<TResult> AdvancedCircuitBreakerAsync<TRe
durationOfBreak,
(outcome, _, timespan, context) => onBreak(outcome, timespan, context),
onReset,
onHalfOpen
);
onHalfOpen);

/// <summary>
/// <para> Builds a <see cref="AsyncPolicy{TResult}"/> that will function like a Circuit Breaker.</para>
Expand Down Expand Up @@ -241,9 +237,9 @@ public static AsyncCircuitBreakerPolicy<TResult> AdvancedCircuitBreakerAsync<TRe
onBreak,
onReset,
onHalfOpen);

return new AsyncCircuitBreakerPolicy<TResult>(
policyBuilder,
breakerController
);
breakerController);
}
}
6 changes: 2 additions & 4 deletions src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class AsyncCircuitBreakerPolicy : AsyncPolicy, ICircuitBreakerPolicy

internal AsyncCircuitBreakerPolicy(
PolicyBuilder policyBuilder,
ICircuitController<EmptyStruct> breakerController
)
ICircuitController<EmptyStruct> breakerController)
: base(policyBuilder) =>
_breakerController = breakerController;

Expand Down Expand Up @@ -64,8 +63,7 @@ public class AsyncCircuitBreakerPolicy<TResult> : AsyncPolicy<TResult>, ICircuit

internal AsyncCircuitBreakerPolicy(
PolicyBuilder<TResult> policyBuilder,
ICircuitController<TResult> breakerController
)
ICircuitController<TResult> breakerController)
: base(policyBuilder) =>
_breakerController = breakerController;

Expand Down
Loading

0 comments on commit 47b2d24

Please sign in to comment.