Skip to content
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
23 changes: 22 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,25 @@ 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

# static fields in PascalCase
dotnet_naming_rule.static_fields_should_have_prefix.severity = warning
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
dotnet_naming_style.static_prefix_style.required_prefix =
dotnet_naming_style.static_prefix_style.capitalization = pascal_case
161 changes: 0 additions & 161 deletions src/.editorconfig

This file was deleted.

33 changes: 17 additions & 16 deletions src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
[Collection(Helpers.Constants.ParallelThreadDependentTestCollection)]
public class BulkheadAsyncSpecs : BulkheadSpecsBase
{
public BulkheadAsyncSpecs(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
public BulkheadAsyncSpecs(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}

#region Configuration

Expand Down Expand Up @@ -50,25 +53,23 @@ public async Task Should_call_onBulkheadRejected_with_passed_context()
Context? contextPassedToOnRejected = null;
Func<Context, Task> onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; };

using (var bulkhead = Policy.BulkheadAsync(1, onRejectedAsync))
using var bulkhead = Policy.BulkheadAsync(1, onRejectedAsync);
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
{
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
{
_ = Task.Run(() => { bulkhead.ExecuteAsync(async () => { await tcs.Task; }); });
_ = Task.Run(() => { bulkhead.ExecuteAsync(async () => { await tcs.Task; }); });

Within(CohesionTimeLimit, () => Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));
Within(CohesionTimeLimit, () => BulkheadSpecsBase.Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));

await bulkhead.Awaiting(b => b.ExecuteAsync(_ => TaskHelper.EmptyTask, contextPassedToExecute)).Should().ThrowAsync<BulkheadRejectedException>();
await bulkhead.Awaiting(b => b.ExecuteAsync(_ => TaskHelper.EmptyTask, contextPassedToExecute)).Should().ThrowAsync<BulkheadRejectedException>();

cancellationSource.Cancel();
tcs.SetCanceled();
}

contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
cancellationSource.Cancel();
tcs.SetCanceled();
}

contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
}

#endregion
Expand All @@ -79,7 +80,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu
Policy.BulkheadAsync(maxParallelization, maxQueuingActions);

protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) =>
action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy) bulkhead);
action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy)bulkhead);

#endregion
}
26 changes: 13 additions & 13 deletions src/Polly.Specs/Bulkhead/BulkheadScenario.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
namespace Polly.Specs.Bulkhead;

internal struct BulkheadScenario
internal readonly struct BulkheadScenario
{
readonly int _maxParallelization;
readonly int _maxQueuingActions;
readonly int _totalTestLoad;
readonly string _scenario;
readonly bool _cancelQueuing;
readonly bool _cancelExecuting;
private readonly int _maxParallelization;
private readonly int _maxQueuingActions;
private readonly int _totalTestLoad;
private readonly string _scenario;
private readonly bool _cancelQueuing;
private readonly bool _cancelExecuting;

public BulkheadScenario(int maxParallelization, int maxQueuingActions, int totalTestLoad, bool cancelQueuing, bool cancelExecuting, string scenario)
{
_maxParallelization = maxParallelization;
_maxQueuingActions = maxQueuingActions;
_totalTestLoad = totalTestLoad;
_scenario = scenario;
_cancelQueuing = cancelQueuing;
_cancelExecuting = cancelExecuting;
_maxParallelization = maxParallelization;
_maxQueuingActions = maxQueuingActions;
_totalTestLoad = totalTestLoad;
_scenario = scenario;
_cancelQueuing = cancelQueuing;
_cancelExecuting = cancelExecuting;
}

public object[] ToTheoryData() =>
Expand Down
31 changes: 16 additions & 15 deletions src/Polly.Specs/Bulkhead/BulkheadSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
[Collection(Helpers.Constants.ParallelThreadDependentTestCollection)]
public class BulkheadSpecs : BulkheadSpecsBase
{
public BulkheadSpecs(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
public BulkheadSpecs(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}

#region Configuration

Expand Down Expand Up @@ -50,24 +53,22 @@ public void Should_call_onBulkheadRejected_with_passed_context()
Context? contextPassedToOnRejected = null;
Action<Context> onRejected = ctx => { contextPassedToOnRejected = ctx; };

using (BulkheadPolicy bulkhead = Policy.Bulkhead(1, onRejected))
{
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
using BulkheadPolicy bulkhead = Policy.Bulkhead(1, onRejected);
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();

Task.Run(() => { bulkhead.Execute(() => { tcs.Task.Wait(); }); });
Task.Run(() => { bulkhead.Execute(() => { tcs.Task.Wait(); }); });

// Time for the other thread to kick up and take the bulkhead.
Within(CohesionTimeLimit, () => Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));
// Time for the other thread to kick up and take the bulkhead.
Within(CohesionTimeLimit, () => BulkheadSpecsBase.Expect(0, () => bulkhead.BulkheadAvailableCount, nameof(bulkhead.BulkheadAvailableCount)));

bulkhead.Invoking(b => b.Execute(_ => { }, contextPassedToExecute)).Should()
.Throw<BulkheadRejectedException>();
bulkhead.Invoking(b => b.Execute(_ => { }, contextPassedToExecute)).Should()
.Throw<BulkheadRejectedException>();

tcs.SetCanceled();
tcs.SetCanceled();

contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
}
contextPassedToOnRejected!.Should().NotBeNull();
contextPassedToOnRejected!.OperationKey.Should().Be(operationKey);
contextPassedToOnRejected!.Should().BeSameAs(contextPassedToExecute);
}

#endregion
Expand All @@ -78,7 +79,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu
Policy.Bulkhead(maxParallelization, maxQueuingActions);

protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) =>
action.ExecuteOnBulkhead((BulkheadPolicy) bulkhead);
action.ExecuteOnBulkhead((BulkheadPolicy)bulkhead);

#endregion
}
Loading