WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

Add to LogEntries before Task completed

Open kelvin-a-law opened this issue 3 years ago • 1 comments

Whilst testing timeout and retry policies I came across an issue where LogEntries were not updated before the test finished. Take this example, not exact code:

// handle 5**, 408,
// retry 3 times with a timeout per retry

var retryPolicy = HttpPolicyExtensions
    .HandleTransientHttpError()
    .Or<TimeoutRejectedException>()
    .RetryAsync(3);

var policy = retryPolicy.WrapAsync(
    HttpPolicy.TimeoutAsync(TimeSpan.FromMilliseconds(300)));

using var server = WireMockServer.Start();

server
    .Given(Request.Create().UsingGet())
    .RespondWith(Response.Create()
        .WithDelay(1000)
        .WithStatusCode(HttpStatusCode.InternalServerError));

var httpClient = CreateHttpClient(policy);

await Assert.ThrowsAsync<TimeoutRejectedException>(() => 
    httpClient.GetAsync(server.Url));

// wiremock leaves recording the requests till the end which means timeouts cause LogEntries to go missing. 
_testOutputHelper.WriteLine("Calls made: " + wireMockServer.LogEntries.Count());

The WithDelay(1000) will cause the policy to timeout (within 300ms), eventually throwing a TimeoutRejectedException, the test will end with a printed line of Calls made: 1 as the other calls are still processing.

Can we add the LogEntry as soon as the request has been received, update when match has been made, with null values for the response, then update it when a response has been created?

kelvin-a-law avatar Oct 17 '22 15:10 kelvin-a-law

@kelvin-a-law This will require some advanced changes in the current logic, I need to think on that if this can be updated, or that';s too much work.

StefH avatar Nov 07 '22 19:11 StefH