Closed rafaelcn closed 2 years ago
Can you please explain more how you are starting MockServer and provide some example code then I should be able to get to the bottom of the problem.
@jamesdbloom, is it still necessary? I was offline when you asked me, but I could still provide the code. Apart from that, I will test the new release to see if it works.
@rafaelcn I think I have fixed the issue in the SNAPSHOT version and added more tests around this so if you still experience the issue please raise a new issue and reference this one.
I will release the SNAPSHOT in the next week or so.
I have the same problem (version 5.15.0), I have two tests and the second test fails unless I sleep for two seconds in the beginning of the test. On the second test it logs: MockServerEventLog - 9000 started on port: 9000 MockServerEventLog - 9000 creating expectation: ... (I call the server) MockServerEventLog - stopped for port: 9000 (I haven't called mockServer.stop()) (I call the server again during the same test) org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:9000/test/Add": An established connection was aborted by the software in your host machine
The first test is similar but it works through the two calls I make to the (mock)server. I call mockServer.stop(true) after each test.
I tried to make minimal two tests that would replicate this, but they worked fine. Here's the setup for each test (Kotlin):
mockServer = ClientAndServer.startClientAndServer(9000)
mockServer!!.`when`(
HttpRequest.request()
.withMethod("POST")
)
.respond(
HttpClassCallback.callback().withCallbackClass(RejectAllResponseCallback::class.java)
)
Describe the issue Whenever I use a MockServer with the same port (necessary, I cannot do using a random port for each unit test) in two or more unit tests the second test to be executed fails. It fails because the first one hasn't stopped the first server using the following procedure:
(This issue has some resemblance with this one: https://github.com/mock-server/mockserver/issues/498)
What you are trying to do Trying to write lots of unit tests that on every and each one of them has a mock server using the same port.
MockServer version 5.11.2
To Reproduce
@AfterClass
with the code provided in the description of this issueExpected behaviour The server stop after the class is finished executing and other tests to be executed with no problems.
MockServer Log Couldn't gather the MockServer log.