Behaviour of ExecuteAndCapture with PolicyWrap and with Fallback
See original GitHub issueI’m wrapping a retry policy in timeout policy. The action returns null so I want to retry.
With retry
policy alone, I get result.Outcome
as Failure
as expected. But with timeout
policy, it is Successful
with result.Result
as null. Shouldn’t it also be a Failure
?
If the action throws, then I see Failure
for both retry
and timeout
policies.
class Holder
{
public bool done;
public Holder holder;
}
[Test]
public async Task Polly_Result_Outcome_Should_Be_Failure()
{
Policy<Holder> retry = Policy
.Handle<Exception>()
.OrResult<Holder>(h =>
{
var flag = !(h?.holder?.done) ?? true;
return flag;
})
.WaitAndRetryAsync(
2,
retryAttempt => TimeSpan.FromMilliseconds(1000));
var timeout = Policy
.TimeoutAsync(10)
.WrapAsync(retry);
var result = await timeout.ExecuteAndCaptureAsync(async (ct) =>
{
ct.ThrowIfCancellationRequested();
//throw new Exception();
return await Task.FromResult((Holder)null);
}, CancellationToken.None)
.ConfigureAwait(false);
if (result.Outcome != OutcomeType.Successful)
{
// retry policy comes here as expected
Assert.Pass();
}
if (result.Result == null)
{
// timeout policy comes here
// why is Outcome not OutcomeType.Failure just like retry policy?
}
Assert.Fail();
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Polly: wrap AsyncFallbackPolicy<TResult> with ...
A non-generic AsyncFallbackPolicy cannot participate in an execution asynchronously returning bool for the reasons stated in the error message: ...
Read more >Building Polly Fallbacks for Resilient .NET Service-to- ...
It will guide you in using the Fallback policy to handle failures you ... the response and determines if its behavior clause should...
Read more >Retry and fallback policies in C# with Polly - Jacob Duijzer
In this blog I will try to explain how one can create clean and effective policies to retry API calls and have fallbacks...
Read more >NET Core Polly (How it Works for Developers)
Fallback policy is used to provide a substitute value or behavior in the event ... Polly will try to execute the underlying delegate...
Read more >Resilience APIs to Transient Faults using Polly - NET Nakama
In our use case, we need to execute an action in our Web API (GetData) ... Combination of Multiple Strategies, Policy Wrap, Different...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing this as I think we’re done here, and we’ve updated the wiki to cover this more precisely. However, if you do need anything else, please re-open the issue or start a fresh one. Also updated the title of the issue for future discoverability. Thanks for your great question!
@rmandvikar Thanks again for your great example which highlights these important points! We’ve updated the documentation for both PolicyWrap and Fallback to make this clearer.
Let us know if there is anything else we can help with.