Unit testing retry policies with timeout intervals
See original GitHub issueCurrently I don’t see a way to unit test a retry policy if you use the time-based retry policy.
Let’s say you use the following approach, and this code below is part of your method that does a few more things than executing the policy itself.
Some code here…
Policy
.Handle<DivideByZeroException>()
.WaitAndRetry(new[]
{
TimeSpan.FromSeconds(30),
TimeSpan.FromSeconds(60),
TimeSpan.FromSeconds(120)
}, (exception, timeSpan) => {
// do something
});
Some code here…
How would I test what happens after we have re-tried 3 times? I don’t want to wait more than one minute in my tests. Thanks for your suggestions.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Unit testing async pessimistic TimeoutPolicy · Issue #623
I am trying to test whether my pessimistic timeout policies work as expected. For this, I tried to mock the function on which...
Read more >Polly verify how many times httpclient timed out/retried in a ...
1 Answer 1 ... The issue is that the test code posted does not return a cancellable Task, at the value mocked for...
Read more >Unit testing HTTP retry strategies | by Madhur
Unit testing HTTP retry strategies ... For example, a very naive HTTP retry strategy to be to retry 3 times at an interval...
Read more >Unit testing Rx methods Timeout & Retry with moq
So I wanted to put Timeout & Retry under test, to do this we use moq for mocking out our dependencies, we also...
Read more >Timeouts, retries and backoff with jitter
The preferred solution that we use in Amazon is a backoff. Instead of retrying immediately and aggressively, the client waits some amount of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
Hi @reisenberger and thanks for your quick reply. I actually just found what I was looking for in Polly itself!
SystemClock.Sleep
allows me to mock the internal timer for Polly, which causes the sleeps to really not sleep.I closed the my issue as it’s not relevant anymore.
Thanks for that @rog1039 . The ability to manipulate Polly’s abstracted, ambient-context SystemClock is intended to provide exactly this: you can manipulate time so that tests which would otherwise incur a time delay, don’t. See the many tests within the existing codebase which do this.
Let us know how you get on with that - or if you can envisage ways it could be improved (I can envisage some - as ever, with trade-offs)
EDIT: Improved the Unit-testing wiki to highlight this.