diff --git a/src/Polly/Timeout/AsyncTimeoutEngine.cs b/src/Polly/Timeout/AsyncTimeoutEngine.cs index 4e4a29fe14b..bebf861c504 100644 --- a/src/Polly/Timeout/AsyncTimeoutEngine.cs +++ b/src/Polly/Timeout/AsyncTimeoutEngine.cs @@ -46,7 +46,7 @@ internal static async Task ImplementationAsync( 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; diff --git a/src/Polly/Timeout/TimeoutEngine.cs b/src/Polly/Timeout/TimeoutEngine.cs index 8b470f67dbd..1f43290acb1 100644 --- a/src/Polly/Timeout/TimeoutEngine.cs +++ b/src/Polly/Timeout/TimeoutEngine.cs @@ -62,7 +62,7 @@ internal static TResult Implementation( 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; diff --git a/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs b/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs index 936ad46ef7c..1c3ca996005 100644 --- a/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs @@ -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(() => policy.ExecuteAsync(async () => + var exception = await Should.ThrowAsync(() => policy.ExecuteAsync(async () => { await SystemClock.SleepAsync(TimeSpan.FromSeconds(3), CancellationToken); })); + + exception.Timeout.ShouldBe(timeout); } [Fact] diff --git a/test/Polly.Specs/Timeout/TimeoutSpecs.cs b/test/Polly.Specs/Timeout/TimeoutSpecs.cs index e42bdb6e97d..351435a09e4 100644 --- a/test/Polly.Specs/Timeout/TimeoutSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutSpecs.cs @@ -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(() => policy.Execute(() => SystemClock.Sleep(TimeSpan.FromSeconds(3), CancellationToken))); + var exception = Should.Throw(() => policy.Execute(() => SystemClock.Sleep(TimeSpan.FromSeconds(3), CancellationToken))); + + exception.Timeout.ShouldBe(timeout); } [Fact]