mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Question: Stub priority - Most recent stub is not always used #91
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 @FSatmar on GitHub (Apr 19, 2018).
Originally assigned to: @StefH on GitHub.
Hi Stef.
It seems that when you have multiple stubs matching the same request, the most recent one is not always used (as expected according to https://github.com/WireMock-Net/WireMock.Net/wiki/Stubbing-and-Request-Matching#stub-priority). Happens to me quite often in tests where I create new stub with diffrent version number for example.
Could you pls check it?
@StefH commented on GitHub (Apr 19, 2018):
The stub-priority should work if you set the priority as described in that chapter.
If you add more mappings which match the same request, there is no logic to take to most recent, I guess you get a random one back...
Does this help you?
@FSatmar commented on GitHub (Apr 20, 2018):
Oh ok, I just read "By default, WireMock.NET will use the most recently added matching stub to satisfy the request." and assumed it's not necessary to use priority if you just always want the latest stub. But anyway, I should be able to increase priority with every 'update'.
@StefH commented on GitHub (Apr 20, 2018):
Ah, ok. I see.
Probably I did copy this from the wiremock.org website, I'll take a look if it's easy to really implement this functionality in the code.
@FSatmar commented on GitHub (Apr 20, 2018):
Btw, wouldn't it make sense to simply overwrite the stub when the new one matches the same request pattern?
@StefH commented on GitHub (Apr 20, 2018):
If you want to overwrite the same, you have to provide the same
guid(in a PUT or POST).Example:
@FSatmar commented on GitHub (Apr 20, 2018):
Hm, that would make my test setup very complicated as I'm creating many different stubs for one test and then i'd have to keep track of the guids when I want to update one of them. For the time being I'll try using the priority as that seems easier to implement.
@StefH commented on GitHub (Apr 20, 2018):
You only need to provide the
guidin the mapping which you can just add or update using http POST. So that should not be extra work.Because if you define the same mapping, but with a different priority, the sever needs to keep all these mappings in memory, and when you want to view the mappings, you get a lot of mapping, and onlt the highest prio is used.
@andreycha commented on GitHub (Apr 25, 2018):
Hi,
I believe it would be easier and more consistent to overwrite existing mapping if Request part is exactly the same, it doesn't make sense to collect mappings with the same request part. Let me explain what I mean:
Now we end up with two mappings which are picked up randomly. But in the scenario when everything is the same in request part, mapping can be safely overwritten.
@StefH commented on GitHub (Apr 26, 2018):
A]
I understand this. I'll check if it's possible to compare the mapping, this has to be built for the mappings defined in code (your example) and also has to implemented in the admin mappings via POST Mapping.
B]
As a workaround, you can use the same
guid, so your code could be like:@StefH commented on GitHub (May 19, 2018):
I just reread your comments and I noticed on your examples: operation 1 and operation 2 are different because they use a different status code.
So they ARE different, always.
What you want is that if the Request is the same, the mapping is overwritten with the latest most recent one.
This requires significant changes in the matching logic, so for now I would suggest to use the
guidorpriority.And for now I will just delete the line By default, WireMock.NET will use the most recently added matching stub to satisfy the request. from the WIKI, because this is indeed not true.
@xadvfh commented on GitHub (Mar 1, 2021):
@StefH I know this is a closed issue but it is something that I'd also be interested in. Keeping track of GUIDs is, unfortunately, not always possible.
@StefH commented on GitHub (Mar 2, 2021):
@xadvfh using an unique GUID is only way the tell mappings apart.
Else I need to check if some things match (like the path) and only change the part that does not match (the status code). This is very difficult.
The only thing I can maybe add is another unique identifier, which can be a string? But I'm not sure this helps you.
@xadvfh commented on GitHub (Mar 2, 2021):
Understood. I think I can make using priority work. thank you.