mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
SaveUnmatchedRequests stopped working #546
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 @LevYas on GitHub (Sep 20, 2023).
Hi! Glad to see the project is thriving! I noticed a little side-effect though :)
Describe the bug
Unmatched requests are no longer saved
Expected behavior:
They should be
Test to reproduce
Other related info
This doesn't work on the latest version 1.5.35, but I see many changes published on Aug 3. I tried to downgrade to version 1.5.32 and it works in 1.5.32, but doesn't work in 1.5.34 and 1.5.35.
The function WriteUnmatchedRequest is not even called in the latest versions. I tested this using my file handler:
If I downgrade to 1.5.32 the breakpoint does hit and the file is successfully saved.
Maybe something has changed in the way the condition is calculated here
59aab9e1c3/src/WireMock.Net/Owin/WireMockMiddleware.cs (L190-L191)@StefH commented on GitHub (Sep 20, 2023):
https://github.com/WireMock-Net/WireMock.Net/pull/1002
@StefH commented on GitHub (Sep 20, 2023):
@LevYas
I have added an extra unit test and changed the code you suggested.
Can you please test preview version 1.5.35-ci-17786 ?
@LevYas commented on GitHub (Sep 20, 2023):
Thank you for such a quick reaction!
I installed this version via MyGet feed, but the error is still reproducible. I'm not sure that the problem is exactly in the line I mentioned - I meant that the match structure/logic might be changed, but I'm not sure.
Does your unit test pass without the modification to the condition line? I don't see the logic changes, for me, it does the same.
Is it possible that an exception is thrown in the request logging? Json serialization in this method can throw.
Not in this line, but if I start debugging with "just my code" disabled, I get JSON serialization error:
In that moment, current string in the json parser is
This happens at the initialization stage:
My mapping
@LevYas commented on GitHub (Sep 20, 2023):
I think I got it. The JSON serialization exception is thrown here
59aab9e1c3/src/WireMock.Net/Owin/WireMockMiddleware.cs (L193)Stack trace
That is why we never reach the WriteUnmatchedRequest.
The exceptions itself is quite strange:
Probably that happened when the serializer tried to serialize BodyAsMimeMessage.
@StefH commented on GitHub (Sep 20, 2023):
Thank you for the analysis.
MimeMessage support is fairly new. However you are not using any Multiparty Mine, correct?
I'll try to use your mapping and debug the code.
Btw thank you for the sponsoring.
@LevYas commented on GitHub (Sep 20, 2023):
UR welcome, happy to help.
I don't use anything like that. My main use case is to write some request-response pairs in proxy mode, disable proxy mode, and use the recordings both as snapshot tests for request factories and tests for response handlers and many other parts of the code that require interaction with third-party API. I work with JSON and XML (SOAP) APIs. Thanks to the speed and convenience of WMN, I don't use mocked unit tests for API-related code.
My pleasure!
@StefH commented on GitHub (Sep 20, 2023):
@LevYas
Can you try preview
1.5.35-ci-17788?@LevYas commented on GitHub (Sep 21, 2023):
That worked, thank you! WriteUnmatchedRequest was called and the file with failed matching is recorded successfully.
@StefH commented on GitHub (Sep 21, 2023):
PR is merged and I'll create a new NuGet version.