Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Async all the things
Await all usages of Awaiting().
  • Loading branch information
martincostello committed Feb 13, 2022
commit caeb817d758381b51f580ea860bac6a8324977a3
6 changes: 3 additions & 3 deletions src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Should_throw_when_onBulkheadRejected_is_null()
#region onBulkheadRejected delegate

[Fact]
public void Should_call_onBulkheadRejected_with_passed_context()
public async Task Should_call_onBulkheadRejected_with_passed_context()
{
string operationKey = "SomeKey";
Context contextPassedToExecute = new Context(operationKey);
Expand All @@ -65,11 +65,11 @@ public void Should_call_onBulkheadRejected_with_passed_context()
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)));

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();
Expand Down
6 changes: 3 additions & 3 deletions src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Should_throw_when_onBulkheadRejected_is_null()
#region onBulkheadRejected delegate

[Fact]
public void Should_call_onBulkheadRejected_with_passed_context()
public async Task Should_call_onBulkheadRejected_with_passed_context()
{
string operationKey = "SomeKey";
Context contextPassedToExecute = new Context(operationKey);
Expand All @@ -66,7 +66,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
{
Task.Run(() => {
_ = Task.Run(() => {
bulkhead.ExecuteAsync(async () =>
{
await tcs.Task;
Expand All @@ -76,7 +76,7 @@ public void Should_call_onBulkheadRejected_with_passed_context()

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

bulkhead.Awaiting(b => b.ExecuteAsync(_ => Task.FromResult(1), contextPassedToExecute)).Should().ThrowAsync<BulkheadRejectedException>();
await bulkhead.Awaiting(b => b.ExecuteAsync(_ => Task.FromResult(1), contextPassedToExecute)).Should().ThrowAsync<BulkheadRejectedException>();

cancellationSource.Cancel();
tcs.SetCanceled();
Expand Down
392 changes: 196 additions & 196 deletions src/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerAsyncSpecs.cs

Large diffs are not rendered by default.

239 changes: 119 additions & 120 deletions src/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ public async Task Should_only_allow_single_execution_on_first_entering_halfopen_

bool firstExecutionActive = false;
// First execution in HalfOpen state: we should be able to verify state is HalfOpen as it executes.
Task firstExecution = Task.Factory.StartNew(() =>
Task firstExecution = Task.Factory.StartNew(async () =>
{
breaker.Awaiting(x => x.ExecuteAsync(async () =>
await breaker.Awaiting(x => x.ExecuteAsync(async () =>
{
firstDelegateExecutedInHalfOpenState = breaker.CircuitState == CircuitState.HalfOpen; // For readability of test results, we assert on this at test end rather than nested in Task and breaker here.

Expand Down Expand Up @@ -581,9 +581,9 @@ public async Task Should_allow_single_execution_per_break_duration_in_halfopen_s

bool firstExecutionActive = false;
// First execution in HalfOpen state: we should be able to verify state is HalfOpen as it executes.
Task firstExecution = Task.Factory.StartNew(() =>
Task firstExecution = Task.Factory.StartNew(async () =>
{
breaker.Awaiting(x => x.ExecuteAsync(async () =>
await breaker.Awaiting(x => x.ExecuteAsync(async () =>
{
firstDelegateExecutedInHalfOpenState = breaker.CircuitState == CircuitState.HalfOpen; // For readability of test results, we assert on this at test end rather than nested in Task and breaker here.

Expand Down Expand Up @@ -656,7 +656,7 @@ await breaker.ExecuteAsync(async () =>
#region Isolate and reset tests

[Fact]
public void Should_open_circuit_and_block_calls_if_manual_override_open()
public async Task Should_open_circuit_and_block_calls_if_manual_override_open()
{
var time = 1.January(2000);
SystemClock.UtcNow = () => time;
Expand All @@ -674,7 +674,7 @@ public void Should_open_circuit_and_block_calls_if_manual_override_open()

// circuit manually broken: execution should be blocked; even non-fault-returning executions should not reset circuit
bool delegateExecutedWhenBroken = false;
breaker.Awaiting(b => b.ExecuteAsync(() => { delegateExecutedWhenBroken = true; return Task.FromResult(ResultPrimitive.Good); }))
await breaker.Awaiting(b => b.ExecuteAsync(() => { delegateExecutedWhenBroken = true; return Task.FromResult(ResultPrimitive.Good); }))
.Should().ThrowAsync<IsolatedCircuitException>();
breaker.CircuitState.Should().Be(CircuitState.Isolated);
breaker.LastException.Should().BeOfType<IsolatedCircuitException>();
Expand All @@ -683,7 +683,7 @@ public void Should_open_circuit_and_block_calls_if_manual_override_open()
}

[Fact]
public void Should_hold_circuit_open_despite_elapsed_time_if_manual_override_open()
public async Task Should_hold_circuit_open_despite_elapsed_time_if_manual_override_open()
{
var time = 1.January(2000);
SystemClock.UtcNow = () => time;
Expand All @@ -702,13 +702,13 @@ public void Should_hold_circuit_open_despite_elapsed_time_if_manual_override_ope
breaker.CircuitState.Should().Be(CircuitState.Isolated);

bool delegateExecutedWhenBroken = false;
breaker.Awaiting(x => x.ExecuteAsync(() => { delegateExecutedWhenBroken = true; return Task.FromResult(ResultPrimitive.Good); }))
await breaker.Awaiting(x => x.ExecuteAsync(() => { delegateExecutedWhenBroken = true; return Task.FromResult(ResultPrimitive.Good); }))
.Should().ThrowAsync<IsolatedCircuitException>();
delegateExecutedWhenBroken.Should().BeFalse();
}

[Fact]
public void Should_close_circuit_again_on_reset_after_manual_override()
public async Task Should_close_circuit_again_on_reset_after_manual_override()
{
var time = 1.January(2000);
SystemClock.UtcNow = () => time;
Expand All @@ -722,12 +722,12 @@ public void Should_close_circuit_again_on_reset_after_manual_override()

breaker.Isolate();
breaker.CircuitState.Should().Be(CircuitState.Isolated);
breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good)))
await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good)))
.Should().ThrowAsync<IsolatedCircuitException>();

breaker.Reset();
breaker.CircuitState.Should().Be(CircuitState.Closed);
breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good))).Should().NotThrowAsync();
await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good))).Should().NotThrowAsync();
}

[Fact]
Expand Down Expand Up @@ -959,7 +959,7 @@ await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive
}

[Fact]
public void Should_not_call_onreset_on_successive_successful_calls()
public async Task Should_not_call_onreset_on_successive_successful_calls()
{
Action<DelegateResult<ResultPrimitive>, TimeSpan> onBreak = (_, _) => { };
bool onResetCalled = false;
Expand All @@ -971,11 +971,11 @@ public void Should_not_call_onreset_on_successive_successful_calls()

onResetCalled.Should().BeFalse();

breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good))).Should().NotThrowAsync();
await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good))).Should().NotThrowAsync();
breaker.CircuitState.Should().Be(CircuitState.Closed);
onResetCalled.Should().BeFalse();

breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good))).Should().NotThrowAsync();
await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good))).Should().NotThrowAsync();
breaker.CircuitState.Should().Be(CircuitState.Closed);
onResetCalled.Should().BeFalse();
}
Expand Down Expand Up @@ -1069,7 +1069,7 @@ await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive
}

[Fact]
public void Should_call_onreset_when_manually_resetting_circuit()
public async Task Should_call_onreset_when_manually_resetting_circuit()
{
int onBreakCalled = 0;
int onResetCalled = 0;
Expand All @@ -1090,15 +1090,15 @@ public void Should_call_onreset_when_manually_resetting_circuit()
onBreakCalled.Should().Be(1);

breaker.CircuitState.Should().Be(CircuitState.Isolated);
breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good)))
await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good)))
.Should().ThrowAsync<IsolatedCircuitException>();

onResetCalled.Should().Be(0);
breaker.Reset();
onResetCalled.Should().Be(1);

breaker.CircuitState.Should().Be(CircuitState.Closed);
breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good)))
await breaker.Awaiting(x => x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good)))
.Should().NotThrowAsync();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Specs/Custom/CustomAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public void Should_be_able_to_construct_active_policy()
}

[Fact]
public void Active_policy_should_execute()
public async Task Active_policy_should_execute()
{
bool preExecuted = false;
AsyncPreExecutePolicy policy = AsyncPreExecutePolicy.CreateAsync(() => { preExecuted = true; return Task.CompletedTask; });

bool executed = false;

policy.Awaiting(x => x.ExecuteAsync(() => { executed = true; return Task.CompletedTask; }))
await policy.Awaiting(x => x.ExecuteAsync(() => { executed = true; return Task.CompletedTask; }))
.Should().NotThrowAsync();

executed.Should().BeTrue();
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Specs/Custom/CustomTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public void Should_be_able_to_construct_active_policy()
}

[Fact]
public void Active_policy_should_execute()
public async Task Active_policy_should_execute()
{
bool preExecuted = false;
AsyncPreExecutePolicy<ResultPrimitive> policy = AsyncPreExecutePolicy<ResultPrimitive>.CreateAsync(() => { preExecuted = true; return Task.CompletedTask; });

bool executed = false;
policy.Awaiting(x => x.ExecuteAsync(async () => { executed = true; await Task.CompletedTask; return ResultPrimitive.Undefined; }))
await policy.Awaiting(x => x.ExecuteAsync(async () => { executed = true; await Task.CompletedTask; return ResultPrimitive.Undefined; }))
.Should().NotThrowAsync();

executed.Should().BeTrue();
Expand Down
Loading