wiremock / wiremock/WireMock.Net

Add to LogEntries before Task completed

Open
#831 1 comment 0 reactions 1 assignee View on GitHub

@StefH is already working on this.

Since Mar 21, 2023.

question
Dominant language
C#
Stars
1.7k
Forks
240
Avg merge
5d 12h
Merged PRs (30d)
2

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.