Unit testing Polly retries in combination with RestEase #224
sverheggen
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I am using RestEase in combinitation with Polly for retries. I like to unit test the polly retries coded. I use xUnit. The following code is executed:
[Fact]
public async void RetryBadPoliciesTest_TransientErrorHttpResponseCode_RetryAsync_IsCalled_Success()
{
// arrange
//var policies = new RetryPolicies();
var messageHandler = new UnitTestMessageHandler(HttpStatusCode.RequestTimeout);
The unit test message handler:
public class UnitTestMessageHandler : DelegatingHandler
{
private HttpStatusCode returnCode;
private int numberOfRequests = 0;
public UnitTestMessageHandler(HttpStatusCode returnCode)
{
this.returnCode = returnCode;
}
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
numberOfRequests++;
return new HttpResponseMessage(this.returnCode);
}
the IHttpTestClient:
public interface IHttpTestClient
{
[Get]
Task GetAsync();
}
When I run the unit test an exception RestEase.API exception is raised that the status code is 428 (TimeOut). The retry isn't executed. Can anyone help with this? Thanks in advanced for your help.
Regards, Stefan Verheggen
Beta Was this translation helpful? Give feedback.
All reactions