Skip to content

Commit 20df9a1

Browse files
addresses #15 by adding a check for wiremock health status
1 parent 950182e commit 20df9a1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

wiremock/server/server.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import socket
55

66
import time
7+
8+
import requests
79
from pkg_resources import resource_filename
810
from subprocess import Popen, PIPE, STDOUT
911

@@ -15,12 +17,13 @@ class WireMockServer(object):
1517
DEFAULT_JAVA = "java" # Assume java in PATH
1618
DEFAULT_JAR = resource_filename("wiremock", "server/wiremock-standalone-2.6.0.jar")
1719

18-
def __init__(self, java_path=DEFAULT_JAVA, jar_path=DEFAULT_JAR):
20+
def __init__(self, java_path=DEFAULT_JAVA, jar_path=DEFAULT_JAR, max_attempts=10):
1921
self.java_path = java_path
2022
self.jar_path = jar_path
2123
self.port = self._get_free_port()
2224
self.__subprocess = None
2325
self.__running = False
26+
self.max_attempts = max_attempts
2427

2528
def __enter__(self):
2629
self.start()
@@ -50,6 +53,19 @@ def start(self):
5053
"\n".join(["returncode: {}".format(self.__subprocess.returncode), "stdout:", str(self.__subprocess.stdout.read())])
5154
)
5255

56+
# Call the /__admin endpoint as a check for running state
57+
attempts = 0
58+
success = False
59+
while attempts < self.max_attempts:
60+
attempts += 1
61+
resp = requests.get("http://localhost:{}/__admin".format(self.port))
62+
if resp.status_code == 200:
63+
success = True
64+
break
65+
66+
if not success:
67+
raise WireMockServerNotStartedError("unable to get a successful GET http://localhost:{}/__admin response".format(self.port))
68+
5369
atexit.register(self.stop, raise_on_error=False)
5470
self.__running = True
5571

0 commit comments

Comments
 (0)