In this blog, I will discuss one troubleshooting tip for Pact Mock Service not stopping, after Pact Contract test completed. The console shows a connection error, not directly related to the solution worked out for me. However, when I stopped Pact Mock Service manually, I was able to proceed with the Pact test.
Background
I am using the following code snippet for starting and stopping Mock Pact Server. I have selected Pact as it helps you to write an integration test without creating expensive infrastructure.
# Setting up pact pact = Consumer('Consumer').has_pact_with(Provider('Provider')) pact.start_service() atexit.register(pact.stop_service) |
However, sometimes Mock service does not stop after the test. This results in connection errors such as Error code 111 as shown in the below screen:
There are some solutions suggested on the internet regarding this problem. I spent almost 2-3 hours searching the root cause of the problem as well as trying out some of those. Fortunately, I got this solution while checking which background processes are running. I thought to blog about this solution so it might help anyone facing a similar problem.
How to stop Pact Mock Service manually?
I used the following steps to overcome this problem. However, note that this not a complete solution in the sense that, once you stop service manually, then you would not require to do it again. The non-stoppage of the Pact Mock Service may still occur. But you can apply the same solution once again.
1. Check if any pact process is still running
2. Kill the process
3. Run the test
1. Check if any pact process is still running
Since pact-mock-service.rb
is ruby file, you can simply type ps aux|grep "ruby"
on the console. This will give all ruby process. You can locate this as shown in the blow screen. Get the pid
for this process which will be used in next step.
2. Kill the proces
Run kill -9 pid
to kill the pact process. You can use the pid which you have found in step 1.
3. Run the test
Now run the test which should be successful now.
I hope the tip mentioned in the above article helps you in case you are facing similar problems. I will be happy to know more about in case you have any other tips to solve the problem mentioned in the above blog.
I have around 15 years of experience in Software Testing. I like tackling Software Testing problems and explore various tools and solutions that can solve those problems. On a personal front, I enjoy reading books during my leisure time.