Set timeout properly for Requests and Thrift connections
This commit is contained in:
@@ -28,7 +28,7 @@ class Connection(object):
|
||||
if url_prefix:
|
||||
url_prefix = '/' + url_prefix.strip('/')
|
||||
self.url_prefix = url_prefix
|
||||
self.timeout = 10
|
||||
self.timeout = timeout
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.host)
|
||||
|
||||
@@ -30,7 +30,7 @@ class Urllib3HttpConnection(Connection):
|
||||
if use_ssl:
|
||||
pool_class = urllib3.HTTPSConnectionPool
|
||||
|
||||
self.pool = pool_class(host, port=port, timeout=kwargs.get('timeout', None), headers=headers, maxsize=maxsize)
|
||||
self.pool = pool_class(host, port=port, timeout=self.timeout, headers=headers, maxsize=maxsize)
|
||||
|
||||
def perform_request(self, method, url, params=None, body=None, timeout=None, ignore=()):
|
||||
url = self.url_prefix + url
|
||||
|
||||
@@ -24,8 +24,15 @@ class TestThriftConnection(TestCase):
|
||||
con = ThriftConnection()
|
||||
self.assertIs(con._tsocket_class, TSocket.TSocket)
|
||||
|
||||
def test_timeout_set(self):
|
||||
con = ThriftConnection(timeout=42)
|
||||
self.assertEquals(42, con.timeout)
|
||||
|
||||
class TestUrllib3Connection(TestCase):
|
||||
def test_timeout_set(self):
|
||||
con = Urllib3HttpConnection(timeout=42)
|
||||
self.assertEquals(42, con.timeout)
|
||||
|
||||
def test_http_auth(self):
|
||||
con = Urllib3HttpConnection(http_auth='username:secret')
|
||||
self.assertEquals({'authorization': 'Basic dXNlcm5hbWU6c2VjcmV0'}, con.pool.headers)
|
||||
@@ -72,6 +79,10 @@ class TestRequestsConnection(TestCase):
|
||||
self.assertEquals(1, len(args))
|
||||
return args[0]
|
||||
|
||||
def test_timeout_set(self):
|
||||
con = RequestsHttpConnection(timeout=42)
|
||||
self.assertEquals(42, con.timeout)
|
||||
|
||||
def test_use_https_if_specified(self):
|
||||
con = self._get_mock_connection({'use_ssl': True, 'url_prefix': 'url'})
|
||||
request = self._get_request(con, 'GET', '/')
|
||||
|
||||
Reference in New Issue
Block a user