mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Mock server not answer if integrated in Xamarin UITest project #313
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 @DellaMoraWalter on GitHub (Nov 6, 2020).
I'm encountering a problem using WireMock.Net in a Xamarin UITest project, currently with Android (iOS not tested yet).
I'm trying to mock my backend, the WireMock instance is created in the UITest project but even if the server is active, the calls are not processed.
I've attached a full example for reproduce the problem, for use remember to align the ip address of the wiremock server with your machine ip address.
If you start the only test defined in MockBackendTests, this fail after the timeout because the call to the wiremock server never gets an answer.
In the solution you can find the 'MockBackendConsole' application that can create an identical instance of wiremock server.
To try it you have to:
I've integrated the solution with the last (v 1.3.5) wiremock.net source code, and set a breackpoint in WireMockMiddleware.cs.
If the mock server is create inside the UITest project, the 'InternalInvoke' function is never called.
Unfortunately I don't understand the problem behind this behavior.
Thanks for support.
MockBackend.zip
@xadvfh commented on GitHub (Nov 26, 2020):
@DellaMoraWalter for some reason WireMock.Net does not work when you set breakpoints. See #510 I also would love to get to the bottom of this.
@DellaMoraWalter commented on GitHub (Dec 5, 2020):
@xadvfh in my attached sample solution the breakpoint works correctly if the wikemock server is started with the console application but don't works if the wiremock server is started inside the UITest project.
So my problem (I think) is not the breackpoints.
Onestly, I'm not sure about how UITest works. Where is executed UITest code, on my machine or in the android simulator?
If is executed in the android simulator, wiremock server has to works or there are restrictions on communication that inibits something?
@StefH commented on GitHub (Dec 5, 2020):
I guess it could also be related to UI threads and background threads in a Xamarin project.
(Maybe starting WireMock.Net in a separate thread/task could help?)
@kcamp commented on GitHub (Dec 15, 2020):
@DellaMoraWalter I am pretty sure I came across this same problem today (and solved it) as I found this issue while doing some research.
My problem looks/acts just like what you're describing (and is also a .NET 4.6.1 project, although we're using xUnit).
I was able to reproduce this in Visual Studio 16.8.3 (for reference only, I don't believe this actually matters).
In our case, we're setting up WireMock to emulate a remote API. The behavior was very similar; we could make the request using our
HttpClient, but ultimately we'd receive a timeout on the client side, with no apparent response or reaction from WireMock. Inspections fornetstat -an | findstr <port>showed that the WireMock implementation was listening correctly, but didn't seem to be handling the request/response cycle fully. Similar inspections in Fiddler seemed to indicate the request was being processed, but the response was never fully completed.Ultimately, I was able to view an unhandled exception in the WireMock internals during the teardown.
Inspecting the Fusion logs, I found that there were two assemblies that were not correctly loading.
System.BuffersandSystem.Numerics.Vectors.Adding just the redirect for the
System.Buffersassembly will result in WireMock immediately returning a 504 status code; further analysis shows the issue withSystem.Numerics.VectorsAdding assembly binding redirects for both of these assemblies to the
app.configof the project made WireMock work correctly, at least for the two machines in our organization that were experiencing the same behavior.I have pushed a very simple repro/fix to a branch
36f446b88d; I did not attempt to run your tests @DellaMoraWalter, but, looking at your attachedMockBackend.zipand general description of the problem, I suspect it might fix your problem. In fact, re-reading your last comment about "it works if it is launched from the console", I am positive this is the case (and that it will fix your tests), since I see that your Consoleapp.configdoes contain the correct redirects already.In that branch,
36f446b88d, the steps to repro are basically this:WireMock.Net.Console.Net461.Classicapplication from the currentfa08d0e617revision.Net461.Classicapplication with these changes(The endpoint being invoked is immaterial, I was able to observe the same issues as a matter of the hosting, not so much individual implementations)
This seems to be vaguely familiar to the behavior described in #393 as well
@StefH This does seem like some sort of issue with the way this is behaving in .NET 4.6.1; not to say it's not purely environmental in our cases. If there is any additional detail I can provide to help diagnose or do a deeper dive to understand the why, please let me know, I'd be happy to provide any details I might be able to.
@StefH commented on GitHub (Dec 16, 2020):
Hello @kcamp, thank you for the research.
@DellaMoraWalter can you try if this workaround solves your issue?
If this indeed solves the issue, I'll add this to a wiki page.
(Note that issue also looks a bit like this one https://github.com/WireMock-Net/WireMock.Net/issues/437)
@DellaMoraWalter commented on GitHub (Dec 16, 2020):
@kcamp, thanks for your very detailed analisys. @StefH, sure I will try the suggested workaround but I need some days because I'm in the middle of a sprint with totally different arguments. I will report you the results of my tests as soon as possible.
@DellaMoraWalter commented on GitHub (Dec 22, 2020):
I've tried the solution proposed by @kcamp and it works perfectly. Referring to the project I've attached to my first post, it was enough to add to the MockBackendTests project an App.config writted like suggested. @kcamp, many thanks again for your help.
@StefH commented on GitHub (Dec 20, 2021):
@DellaMoraWalter
Can you try preview:
1.4.29-ci-15689?Info : https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
@StefH commented on GitHub (Dec 24, 2021):
@DellaMoraWalter
I've added
ConfigureAwait(false)to allawaitcalls, so maybe this will solve your issue.I'm closing this issue now, a new official version will be released in some days.
https://github.com/WireMock-Net/WireMock.Net/pull/704