Add to LogEntries before Task completed #461

Open
opened 2025-12-29 15:24:23 +01:00 by adam · 1 comment
Owner

Originally created by @kelvin-a-law on GitHub (Oct 17, 2022).

Originally assigned to: @StefH on GitHub.

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?

Originally created by @kelvin-a-law on GitHub (Oct 17, 2022). Originally assigned to: @StefH on GitHub. 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: ``` c# // 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?
adam added the question label 2025-12-29 15:24:23 +01:00
Author
Owner

@StefH commented on GitHub (Nov 7, 2022):

@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 commented on GitHub (Nov 7, 2022): @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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#461