Commit 2640aeba authored by Łukasz Nowak's avatar Łukasz Nowak

promise/plugin: check_url_available cover timeout

parent dfff75f2
......@@ -41,9 +41,16 @@ HTTPS_ENDPOINT = "http://%s:%s/" % (SLAPOS_TEST_IPV4, SLAPOS_TEST_IPV4_PORT)
class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
timeout = int(self.headers.dict.get('timeout', '0'))
path = self.path.split('/')[-1]
if '_' in path:
response, timeout = path.split('_')
response = int(response)
timeout = int(timeout)
else:
timeout = 0
response = int(path)
time.sleep(timeout)
response = int(self.path.split('/')[-1])
self.send_response(response)
self.send_header("Content-type", "application/json")
......@@ -54,8 +61,7 @@ class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.wfile.write(json.dumps(response, indent=2))
class TestCheckUrlAvailable(TestPromisePluginMixin):
class CheckUrlAvailableMixin(TestPromisePluginMixin):
@classmethod
def setUpClass(cls):
server = BaseHTTPServer.HTTPServer(
......@@ -99,6 +105,9 @@ extra_config_dict = {
def tearDown(self):
TestPromisePluginMixin.tearDown(self)
class TestCheckUrlAvailable(CheckUrlAvailableMixin):
def test_check_url_bad(self):
content = self.base_content % {
'url': 'https://',
......@@ -247,5 +256,26 @@ extra_config_dict = {
)
class TestCheckUrlAvailableTimeout(CheckUrlAvailableMixin):
def test_check_200_timeout(self):
url = HTTPS_ENDPOINT + '200_5'
content = self.base_content % {
'url': url,
'timeout': 1,
'check_secure': 0,
'ignore_code': 0,
}
self.writePromise(self.promise_name, content)
self.configureLauncher()
with self.assertRaises(PromiseError):
self.launcher.run()
result = self.getPromiseResult(self.promise_name)
self.assertEqual(result['result']['failed'], True)
self.assertEqual(
result['result']['message'],
"Error: Promise timed out after 0.5 seconds",
)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment