Change the API of wait_any_url to return a tuple of url and response
Previously wait_any_url returned the first url which responded correctly, but there was no way to actually retrieve its response. Change-Id: I41aec4fa1f0a5007af70e787a5503ffeb539c783
This commit is contained in:
parent
1a307e3af3
commit
eeddd30116
@ -29,8 +29,10 @@ class UrlHelperWaitForUrlsTest(test.TestCase):
|
|||||||
url, body=b'no worky',
|
url, body=b'no worky',
|
||||||
status=400)
|
status=400)
|
||||||
|
|
||||||
url = url_helper.wait_any_url(urls)
|
url, response = url_helper.wait_any_url(urls)
|
||||||
self.assertEqual("http://www.yahoo.com", url)
|
self.assertEqual("http://www.yahoo.com", url)
|
||||||
|
self.assertIsInstance(response, url_helper.RequestsResponse)
|
||||||
|
self.assertEqual(response.contents, b'it worked!')
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
def test_url_wait_for_no_work(self):
|
def test_url_wait_for_no_work(self):
|
||||||
|
@ -226,6 +226,9 @@ def wait_any_url(urls, max_wait=None, timeout=None,
|
|||||||
service but is not going to find one. It is possible that the instance
|
service but is not going to find one. It is possible that the instance
|
||||||
data host (169.254.169.254) may be firewalled off Entirely for a sytem,
|
data host (169.254.169.254) may be firewalled off Entirely for a sytem,
|
||||||
meaning that the connection will block forever unless a timeout is set.
|
meaning that the connection will block forever unless a timeout is set.
|
||||||
|
|
||||||
|
This will return a tuple of the first url which succeeded and the
|
||||||
|
response object.
|
||||||
"""
|
"""
|
||||||
start_time = now()
|
start_time = now()
|
||||||
|
|
||||||
@ -268,7 +271,7 @@ def wait_any_url(urls, max_wait=None, timeout=None,
|
|||||||
url_exc = UrlError(ValueError(reason), code=response.code,
|
url_exc = UrlError(ValueError(reason), code=response.code,
|
||||||
headers=response.headers)
|
headers=response.headers)
|
||||||
else:
|
else:
|
||||||
return url
|
return url, response
|
||||||
except UrlError as e:
|
except UrlError as e:
|
||||||
reason = "request error [%s]" % e
|
reason = "request error [%s]" % e
|
||||||
url_exc = e
|
url_exc = e
|
||||||
|
Loading…
x
Reference in New Issue
Block a user