mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Mappings could have a remaining hit counter that upon reaching 0 would stop being considered #318
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @edabreu on GitHub (Dec 2, 2020).
Is your feature request related to a problem? Please describe.
I've recently replaced the use of MockServer with WireMock.net. The main issue that I've found so far is not being able to setup stubs/expectations to have a counter to control its availability. Let's imagine the scenario where I want to simulate the recovery from a failure when calling an external service. Imagining that I have a Polly retry policy for http transient errors I would like to test a scenario where, for example, the first N attempts would return status 5XX, and after that I could have a successful one returning 200.
Describe the solution you'd like
In order for this to test I would like to be able to setup a stub that would respond with status 5XX for the first N calls with priority 1 and another stub that would respond with a payload and status 200 with priority 2. Both stubs would match the same request, but the first one would only match while the defined counter was greater than 0.
Describe alternatives you've considered
Taking into consideration the previously presented communication's recovery scenario I don't think that any of the existing alternatives (timeouts, random timeouts, mixed priorities) would allow this to be tested because once a stub is created it will be there until a reset is made.
Is your feature request supported by WireMock (java version)? Please provide details.
It is my understanding that the java version also doesn't support this.
@StefH commented on GitHub (Dec 2, 2020):
Hello @edabreu,
I think your question can be solved by using https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States
Particularly, in your case, "https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States#stay-in-the-same-state-for-a-number-of-requests" would be solution.
@edabreu commented on GitHub (Dec 4, 2020):
Hello @StefH
Thank you for clearing this issue. I've successfully created a test scenario as mentioned before using the Scenario states, but I've been trying to setup another scenario as follows:
On my service I have a timeout of 500ms. I can't manage to have this scenario working because the wiremock is stuck in the first state, always responding with a delay of 600ms for all retry attempts. I think that wiremock might not be updating its scenario state because my service is closing the connection due to timeout. Or am I doing something wrong?
@StefH commented on GitHub (Dec 4, 2020):
Quick answer:
.WithHeader("Content-Type", "application/json")should also be added to the second part ?And what you can do is observe the logging, maybe you see some details there why is it's not matching?
@edabreu commented on GitHub (Dec 11, 2020):
Thank you for all the help.