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
2 changes: 1 addition & 1 deletion src/Polly/Timeout/AsyncTimeoutEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
if (ex is OperationCanceledException && timeoutCancellationTokenSource.IsCancellationRequested)
{
await onTimeoutAsync(context, timeout, actionTask, ex).ConfigureAwait(continueOnCapturedContext);
throw new TimeoutRejectedException("The delegate executed asynchronously through TimeoutPolicy did not complete within the timeout.", ex);
throw new TimeoutRejectedException("The delegate executed asynchronously through TimeoutPolicy did not complete within the timeout.", timeout, ex);
}

throw;
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Timeout/TimeoutEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal static TResult Implementation<TResult>(
if (ex is OperationCanceledException && timeoutCancellationTokenSource.IsCancellationRequested)
{
onTimeout(context, timeout, actionTask, ex);
throw new TimeoutRejectedException("The delegate executed through TimeoutPolicy did not complete within the timeout.", ex);
throw new TimeoutRejectedException("The delegate executed through TimeoutPolicy did not complete within the timeout.", timeout, ex);
}

throw;
Expand Down
4 changes: 3 additions & 1 deletion test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,12 @@ public async Task Should_throw_when_timeout_is_less_than_execution_duration__pes

var policy = Policy.TimeoutAsync(timeout, TimeoutStrategy.Pessimistic);

await Should.ThrowAsync<TimeoutRejectedException>(() => policy.ExecuteAsync(async () =>
var exception = await Should.ThrowAsync<TimeoutRejectedException>(() => policy.ExecuteAsync(async () =>
{
await SystemClock.SleepAsync(TimeSpan.FromSeconds(3), CancellationToken);
}));

exception.Timeout.ShouldBe(timeout);
}

[Fact]
Expand Down
7 changes: 5 additions & 2 deletions test/Polly.Specs/Timeout/TimeoutSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,12 @@ public void Should_be_able_to_configure_without_an_exception()
[Fact]
public void Should_throw_when_timeout_is_less_than_execution_duration__pessimistic()
{
var policy = Policy.Timeout(TimeSpan.FromMilliseconds(50), TimeoutStrategy.Pessimistic);
var timeout = TimeSpan.FromMilliseconds(50);
var policy = Policy.Timeout(timeout, TimeoutStrategy.Pessimistic);

Should.Throw<TimeoutRejectedException>(() => policy.Execute(() => SystemClock.Sleep(TimeSpan.FromSeconds(3), CancellationToken)));
var exception = Should.Throw<TimeoutRejectedException>(() => policy.Execute(() => SystemClock.Sleep(TimeSpan.FromSeconds(3), CancellationToken)));

exception.Timeout.ShouldBe(timeout);
}

[Fact]
Expand Down
Loading