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

Use the same analyzers for V7 projects #1287

Merged
merged 5 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 12 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ tab_width = 2
dotnet_code_quality.CA1062.null_check_validation_methods = NotNull

# S2094 // Classes should not be empty
dotnet_diagnostic.S2094.severity = suggestion
dotnet_diagnostic.S2094.severity = suggestion

# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = true:error
csharp_style_expression_bodied_constructors = true:error
csharp_style_expression_bodied_operators = true:error
csharp_place_expr_method_on_single_line = false

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:error
csharp_style_expression_bodied_indexers = true:error
csharp_style_expression_bodied_accessors = true:error
161 changes: 0 additions & 161 deletions src/.editorconfig

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Polly.Core.Tests.Hedging.Controller;
public class HedgingExecutionContextTests : IDisposable
{
private const string Handled = "Handled";
private static readonly TimeSpan AssertTimeout = TimeSpan.FromSeconds(5);
private static readonly TimeSpan _assertTimeout = TimeSpan.FromSeconds(5);
martincostello marked this conversation as resolved.
Show resolved Hide resolved
private readonly ResiliencePropertyKey<string> _myKey = new("my-key");
private readonly CancellationTokenSource _cts;
private readonly HedgingTimeProvider _timeProvider;
Expand Down Expand Up @@ -390,8 +390,8 @@ public async Task Complete_EnsurePendingTasksCleaned()

await pending;

assertPrimary.WaitOne(AssertTimeout).Should().BeTrue();
assertSecondary.WaitOne(AssertTimeout).Should().BeTrue();
assertPrimary.WaitOne(_assertTimeout).Should().BeTrue();
assertSecondary.WaitOne(_assertTimeout).Should().BeTrue();
}

[Fact]
Expand All @@ -408,7 +408,7 @@ public async Task Complete_EnsureCleaned()
context.LoadedTasks.Should().Be(0);
context.Snapshot.Context.Should().BeNull();

_onReset.WaitOne(AssertTimeout);
_onReset.WaitOne(_assertTimeout);
_resets.Count.Should().Be(1);
_returnedExecutions.Count.Should().Be(2);
}
Expand Down
30 changes: 15 additions & 15 deletions src/Polly.Core.Tests/Hedging/HedgingResilienceStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class HedgingResilienceStrategyTests : IDisposable

private const string Failure = "Failure";

private static readonly TimeSpan LongDelay = TimeSpan.FromDays(1);
private static readonly TimeSpan AssertTimeout = TimeSpan.FromSeconds(15);
private static readonly TimeSpan _longDelay = TimeSpan.FromDays(1);
private static readonly TimeSpan _assertTimeout = TimeSpan.FromSeconds(15);

private readonly HedgingStrategyOptions _options = new();
private readonly List<TelemetryEventArguments> _events = new();
Expand Down Expand Up @@ -134,7 +134,7 @@ public async void ExecuteAsync_EnsureHedgedTasksCancelled_Ok()
try
{
_testOutput.WriteLine("Hedged task executing...");
await Task.Delay(LongDelay, context.CancellationToken);
await Task.Delay(_longDelay, context.CancellationToken);
_testOutput.WriteLine("Hedged task executing...done (not-cancelled)");
}
catch (OperationCanceledException)
Expand Down Expand Up @@ -168,7 +168,7 @@ public async void ExecuteAsync_EnsureHedgedTasksCancelled_Ok()

_timeProvider.Advance(TimeSpan.FromHours(1));
(await result).Should().Be(Success);
cancelled.WaitOne(AssertTimeout).Should().BeTrue();
cancelled.WaitOne(_assertTimeout).Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -226,13 +226,13 @@ public async Task ExecuteAsync_EnsureDiscardedResultDisposed()
var result = await strategy.ExecuteAsync(async token =>
{
#pragma warning disable CA2016 // Forward the 'CancellationToken' parameter to methods
await _timeProvider.Delay(LongDelay);
await _timeProvider.Delay(_longDelay);
#pragma warning restore CA2016 // Forward the 'CancellationToken' parameter to methods
return primaryResult;
});

// assert
_timeProvider.Advance(LongDelay);
_timeProvider.Advance(_longDelay);

await primaryResult.WaitForDisposalAsync();
primaryResult.IsDisposed.Should().BeTrue();
Expand Down Expand Up @@ -277,7 +277,7 @@ public async Task ExecuteAsync_EveryHedgedTaskShouldHaveDifferentContexts()
context.Properties.GetValue(beforeKey, "wrong").Should().Be("before");
context.Should().Be(primaryContext);
contexts.Add(context);
await _timeProvider.Delay(LongDelay, context.CancellationToken);
await _timeProvider.Delay(_longDelay, context.CancellationToken);
return "primary";
},
primaryContext,
Expand All @@ -286,7 +286,7 @@ public async Task ExecuteAsync_EveryHedgedTaskShouldHaveDifferentContexts()
// assert
contexts.Should().HaveCountGreaterThan(1);
contexts.Count.Should().Be(contexts.Distinct().Count());
_timeProvider.Advance(LongDelay);
_timeProvider.Advance(_longDelay);
tokenHashCodes.Distinct().Should().HaveCountGreaterThan(1);
}

Expand Down Expand Up @@ -501,8 +501,8 @@ public async Task ExecuteAsync_CancellationLinking_Ok()
_timeProvider.Advance(TimeSpan.FromHours(1));
await task.Invoking(async t => await t).Should().ThrowAsync<OperationCanceledException>();

primaryCancelled.WaitOne(AssertTimeout).Should().BeTrue();
secondaryCancelled.WaitOne(AssertTimeout).Should().BeTrue();
primaryCancelled.WaitOne(_assertTimeout).Should().BeTrue();
secondaryCancelled.WaitOne(_assertTimeout).Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -556,8 +556,8 @@ public async void ExecuteAsync_ZeroHedgingDelay_EnsureAllTasksSpawnedAtOnce()
var task = Create().ExecuteAsync(async c => (await Execute(c)).Result, default);

// assert
Assert.True(allExecutionsReached.WaitOne(AssertTimeout));
_timeProvider.Advance(LongDelay);
Assert.True(allExecutionsReached.WaitOne(_assertTimeout));
_timeProvider.Advance(_longDelay);
await task;

async ValueTask<Outcome<string>> Execute(CancellationToken token)
Expand All @@ -567,7 +567,7 @@ async ValueTask<Outcome<string>> Execute(CancellationToken token)
allExecutionsReached.Set();
}

await _timeProvider.Delay(LongDelay, token);
await _timeProvider.Delay(_longDelay, token);
return Success.AsOutcome();
}
}
Expand All @@ -585,7 +585,7 @@ public void ExecuteAsync_InfiniteHedgingDelay_EnsureNoConcurrentExecutions()
var pending = Create().ExecuteAsync(Execute, _cts.Token);

// assert
Assert.True(allExecutions.WaitOne(AssertTimeout));
Assert.True(allExecutions.WaitOne(_assertTimeout));

async ValueTask<Outcome<string>> Execute(CancellationToken token)
{
Expand All @@ -602,7 +602,7 @@ async ValueTask<Outcome<string>> Execute(CancellationToken token)
allExecutions.Set();
}

await _timeProvider.Delay(LongDelay, token);
await _timeProvider.Delay(_longDelay, token);

return "dummy".AsOutcome();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Core/CircuitBreaker/Health/HealthMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace Polly.CircuitBreaker.Health;
internal abstract class HealthMetrics
{
private const short NumberOfWindows = 10;
private static readonly TimeSpan ResolutionOfCircuitTimer = TimeSpan.FromMilliseconds(20);
private static readonly TimeSpan _resolutionOfCircuitTimer = TimeSpan.FromMilliseconds(20);

protected HealthMetrics(TimeProvider timeProvider) => TimeProvider = timeProvider;

public static HealthMetrics Create(TimeSpan samplingDuration, TimeProvider timeProvider)
{
return samplingDuration < TimeSpan.FromTicks(ResolutionOfCircuitTimer.Ticks * NumberOfWindows)
return samplingDuration < TimeSpan.FromTicks(_resolutionOfCircuitTimer.Ticks * NumberOfWindows)
? new SingleHealthMetrics(samplingDuration, timeProvider)
: new RollingHealthMetrics(samplingDuration, NumberOfWindows, timeProvider);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Polly.Core/ResilienceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class ResilienceContext
{
private const bool ContinueOnCapturedContextDefault = false;

private static readonly ObjectPool<ResilienceContext> Pool = new(static () => new ResilienceContext(), static c => c.Reset());
private static readonly ObjectPool<ResilienceContext> _pool = new(static () => new ResilienceContext(), static c => c.Reset());

private readonly List<ResilienceEvent> _resilienceEvents = new();

Expand Down Expand Up @@ -74,7 +74,7 @@ private ResilienceContext()
/// After the execution is finished you should return the <see cref="ResilienceContext"/> back to the pool
/// by calling <see cref="Return(ResilienceContext)"/> method.
/// </remarks>
public static ResilienceContext Get() => Pool.Get();
public static ResilienceContext Get() => _pool.Get();

internal void InitializeFrom(ResilienceContext context)
{
Expand All @@ -95,7 +95,7 @@ public static void Return(ResilienceContext context)
{
Guard.NotNull(context);

Pool.Return(context);
_pool.Return(context);
}

[ExcludeFromCodeCoverage]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Polly.Extensions.Tests;

public class ReloadableResilienceStrategyTests
{
private static readonly ResiliencePropertyKey<string> TagKey = new("tests.tag");
private static readonly ResiliencePropertyKey<string> _tagKey = new("tests.tag");

[InlineData(null)]
[InlineData("custom-name")]
Expand Down Expand Up @@ -47,14 +47,14 @@ public void AddResilienceStrategy_EnsureReloadable(string? name)

// initial
strategy.Execute(_ => "dummy", context);
context.Properties.GetValue(TagKey, string.Empty).Should().Be("initial-tag");
context.Properties.GetValue(_tagKey, string.Empty).Should().Be("initial-tag");

// reloads
for (int i = 0; i < 10; i++)
{
reloadableConfig.Reload(new() { { "tag", $"reload-{i}" } });
strategy.Execute(_ => "dummy", context);
context.Properties.GetValue(TagKey, string.Empty).Should().Be($"reload-{i}");
context.Properties.GetValue(_tagKey, string.Empty).Should().Be($"reload-{i}");
}

registry.Count.Should().Be(1);
Expand Down Expand Up @@ -101,7 +101,7 @@ protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>
ResilienceContext context,
TState state)
{
context.Properties.Set(TagKey, Tag);
context.Properties.Set(_tagKey, Tag);
return callback(context, state);
}
}
Expand Down
Loading