From 315b9a82618e612c0d0c2964cdecea219fe33687 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 29 Apr 2016 20:49:28 -0500 Subject: Add a simple __main__ to easily show healthcheck output Seems like not many people know what the detailed output of this thing does, so in order to make it easier to see that add a simple __main__ entrypoint. Change-Id: Ife3b49c29df7d3558efebb4584971cf69bc8359d --- oslo_middleware/tests/test_healthcheck.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'oslo_middleware/tests') diff --git a/oslo_middleware/tests/test_healthcheck.py b/oslo_middleware/tests/test_healthcheck.py index 3ffb03f..19fc63a 100644 --- a/oslo_middleware/tests/test_healthcheck.py +++ b/oslo_middleware/tests/test_healthcheck.py @@ -13,12 +13,36 @@ # License for the specific language governing permissions and limitations # under the License. +import threading +import time + import mock from oslotest import base as test_base +import requests import webob.dec import webob.exc from oslo_middleware import healthcheck +from oslo_middleware.healthcheck import __main__ + + +class HealthcheckMainTests(test_base.BaseTestCase): + + def test_startup_response(self): + server = __main__.create_server(0) + th = threading.Thread(target=server.serve_forever) + th.start() + self.addCleanup(server.shutdown) + while True: + try: + r = requests.get("http://%s:%s" % (server.server_address[0], + server.server_address[1])) + except requests.ConnectionError: + # Server hasn't started up yet, try again in a few. + time.sleep(1) + else: + self.assertEqual(200, r.status_code) + break class HealthcheckTests(test_base.BaseTestCase): -- cgit v1.2.1