question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Must be able to assert result from Polly in unit tests

See original GitHub issue

There’s the noOp policy that is recommended to be used in tests. This class allows your code to bypass polly itself, ignoring timeouts for example (which is our case).

This is all great, but we must be able to assert the TimeoutRejectedException from polly. I guess what we want to do is to “fake” the noOp policy to always have a FinalException set. Is this possible?

In essence, we want to;

  1. Write code dependent on the timeout policy.
  2. Inject noOp policy in our tests
  3. Make polly return TimeoutRejectedException, even though not applying the real timeout policy (because of obvious reasons)
  4. Assert our code behaves correctly on the policy result. (We make decisions based on the FinalException property on the policy result)

I’ve tried to narrow this down as much as I can while still making it useful and hopefully understandable.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
reisenbergercommented, Oct 7, 2017

@jiimaho Added to the Polly [unit-testing documentation)(https://github.com/App-vNext/Polly/wiki/Unit-testing-with-Polly), to reflect this approach.

0reactions
reisenbergercommented, Oct 7, 2017

Close via #317

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Polly retry unit test
It allows you to inject exceptions, return BadRequests and etc. in order to trigger Polly's fault and resilience policies such as WaitAndRetry ....
Read more >
Testing Your Code When Using Polly | no dogma blog
What my code should do if there was no policy in place. I have a few classes to demonstrate these scenarios, BusinessLogic.cs and ......
Read more >
Must be able to assert result from Polly in unit tests
There's the noOp policy that is recommended to be used in tests. This class allows your code to bypass polly itself, ignoring timeouts...
Read more >
Build a resilient .NET service with Polly Retry Policy and ...
Writing a solid and resilient cloud service requires writing quality unit tests. Good unit tests will give developers confidence and improve code quality....
Read more >
Retry and fallback policies in C# with Polly - Jacob Duijzer
Let's try and create a unit test to test the behavior of the circuit breaker. After adding some logging to the service and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found