{"id":13914,"date":"2020-11-04T09:05:00","date_gmt":"2020-11-04T14:05:00","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=13914"},"modified":"2020-12-01T03:54:12","modified_gmt":"2020-12-01T08:54:12","slug":"stop-pact-mock-services-manually","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/stop-pact-mock-services-manually\/","title":{"rendered":"How to stop Pact Mock Service manually?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In this blog, I will discuss one troubleshooting tip for <a href=\"https:\/\/pypi.org\/project\/pact-python\/\">Pact<\/a> 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.<br \/>\n<\/span><\/p>\n<hr>\n<h3>Background<\/h3>\n<p>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.<\/p>\n<pre lang=\"python\"># Setting up pact\npact = Consumer('Consumer').has_pact_with(Provider('Provider'))\npact.start_service()\natexit.register(pact.stop_service)\n<\/pre>\n<p>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:<\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/10\/Mock-Service-error-1.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/10\/Mock-Service-error-1.png\" alt=\"\"><\/a><\/p>\n<p>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.<\/p>\n<hr>\n<h3>How to stop Pact Mock Service manually?<\/h3>\n<p>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.<\/p>\n<p>1. Check if any pact process is still running<br \/>\n2. Kill the process<br \/>\n3. Run the test<\/p>\n<hr>\n<h5>1. Check if any pact process is still running<\/h5>\n<p>Since <code>pact-mock-service.rb<\/code> is ruby file, you can simply type <code>ps aux|grep \"ruby\"<\/code> on the console. This will give all ruby process. You can locate this as shown in the blow screen. Get the <code>pid<\/code> for this process which will be used in next step.<\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/10\/Mock-Service-grep.png\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/10\/Mock-Service-grep.png\" alt=\"\"><\/a><\/p>\n<hr>\n<h5>2. Kill the proces<\/h5>\n<p>Run <code>kill -9 pid<\/code> to kill the pact process. You can use the pid which you have found in step 1.<\/p>\n<hr>\n<h5>3. Run the test<\/h5>\n<p>Now run the test which should be successful now.<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/10\/Mock-Service-test-log.png\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/10\/Mock-Service-test-log.png\" alt=\"\"><\/a><\/p>\n<hr>\n<p>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.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[262,263],"tags":[],"class_list":["post-13914","post","type-post","status-publish","format-standard","hentry","category-pact","category-pact-mock-service"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/13914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=13914"}],"version-history":[{"count":14,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/13914\/revisions"}],"predecessor-version":[{"id":14597,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/13914\/revisions\/14597"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=13914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=13914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=13914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}