mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Request for an API for WaitOnExit in StandAlone scenario[Solved] #342
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 @ZenwalkerD on GitHub (Mar 20, 2021).
Originally assigned to: @StefH on GitHub.
Is your feature request related to a problem? Please describe.
In my integration tests, i am using Standalone style of using Wiremock. And i am following below example https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.StandAlone.NETCoreApp/Program.cs as a template to start with.
I do not want to make it a Windows Service because in my pipeline; i do not have Admin rights to install it as service. Neither i can make it a Web app because IIS is not available in pipeline.
However, in my case, since no manual intervention can be done; so i am just sleeping infinitely rather than taking an Console key entry to close the app/process.
Describe the solution you'd like
An API similar to Process.WaitForExit(), can be provided. That way i need not need to kill the process when the process is sleeping indefinitely (standalone).
I can issue WiremockServer.Stop(); then WaitForExit() will allow the control flow to end just like how Process.WaitForExit behaves.
Describe alternatives you've considered
Killing the process.
Is your feature request supported by WireMock (java version)? Please provide details.
Not sure. I do not use java version.
Additional context
None
@StefH commented on GitHub (Mar 20, 2021):
Do you mean this scenario?
1.
You start the WireMock.Net using a console app, just like WireMock.Net.StandAlone.NETCoreApp
2.
You removed the code which handles
Ctrl+C3.
But what next ? How can you stop the console-app ?
Do you want to post a Stop-command to the Admin interface to stop WireMock.Net?
or
Do you just want to use
WaitForExit(timeout)-> this is already possible ?@ZenwalkerD commented on GitHub (Mar 20, 2021):
Let me explain with the code below...
I created a windows form App (without form) with Main Function as shown:
Now i created another class in another project to start above app as shown below:
As u can see above from class MockServerProcessHandler. I start the exe process which actually starts the mockserver.
p.s: Sorry, github is screwing up the formatting of code pasted. I tried to fix, it aint indenting
@StefH commented on GitHub (Mar 20, 2021):
I'm trying to understand your request....
Quick question : why don't you use WireMock.Net in a unit-testing scenario (https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests) ?
@ZenwalkerD commented on GitHub (Mar 22, 2021):
Ok let me explain my scenario here.
I am doing Integration Testing.
I have a DotNET Core WebAPI application.
I run my WebAPI on localhost. The integration test cases call my APIs exposed in WebAPI app using HttpClient (localhost/api/xxxx).
The WebAPI internally calls external API services (assume weather API).
So in my integration tests shown code in my previous post; the mockserver is used to mock the external APIs which is called by the WebAPI and not from Integration Tests.
Hence, in my integration tests i start mockserver as an independent process on port 9500; so that my webAPI app can invoke API requests on that port on localhost instead of actual external API.
Note: I tried the Unit testing style (link given by you) it wont work. Server starts, but from postman i can not use the api stubbed by wiremock.
@StefH commented on GitHub (Mar 22, 2021):
Another possibility is that you just keep the always WireMock.Net server running and just reset all mappings (via the admin interface) before you start your test.
Or you can also run the WireMock.Net server as a docker image and just kill/stop the container after the test?
@ZenwalkerD commented on GitHub (Mar 22, 2021):
I can not do the reset map and again map as i am suppose to run the wiremock as an independent process.
So once the process starts, i wont be able to reset before every tests otherwise i will have to implement IPC. Which is a huge task.
Btw, not allowed to use Docket in pipeline. Hence using as a process.
But i wish to know how to close the process without killing it. I do not want to use Thread.Sleep after i run mockserver start API.
Because i am running Thread.Sleep; i am forced to kill the process.
@StefH commented on GitHub (Mar 22, 2021):
1.
IPC is not needed.
When the WireMock.Net server starts, you can call the admin API (via post/get rest commands) to add or reset the mappings. (https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference#__adminmappings) that's the whole idea, you can start the server once, and before each test, just add the mappings you need.
2.
What do you mean by close the process? Why can't you just kill it?
Like:
@ZenwalkerD commented on GitHub (Mar 22, 2021):
Killing is bad ;)
Any way, i came up with a simple way to safely close the application rather than killing. Its working without much hassle. ;)
I am using ManualResetEvent. In Main func, i make ManualResetEvent to wait.
Then in one of the API request; i just notify it to close. ;)
Console App:
Process starter:
Thanks for your time. :)