summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2018-06-22 16:49:03 -0700
committerTim Burke <tim.burke@gmail.com>2018-11-09 09:55:30 -0800
commit411ef48e5bca1ed66a2e4dd7ecd8695e2bf6c94e (patch)
tree39b0b0e6f4626135e374d2943392ecb90a4cf2c4 /tests
parent9acdfe0b460048420551bb84fb3cf41fb1e4a67e (diff)
downloadpython-swiftclient-411ef48e5bca1ed66a2e4dd7ecd8695e2bf6c94e.tar.gz
Stop leaking quite so many connections
While investigating the failures when you move func tests to py3, I noticed a whole bunch of ResourceWarning: unclosed <socket.socket ...> noise. This should fix it. While we're at it, make get_capabilities less stupid. Change-Id: I3913e9334090b04a78143e0b70f621aad30fc642 Related-Change: I86d24104033b490a35178fc504d88c1e4a566628
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/test_swiftclient.py1
-rw-r--r--tests/unit/test_swiftclient.py8
-rw-r--r--tests/unit/utils.py11
3 files changed, 17 insertions, 3 deletions
diff --git a/tests/functional/test_swiftclient.py b/tests/functional/test_swiftclient.py
index 0380d96..1d76a8d 100644
--- a/tests/functional/test_swiftclient.py
+++ b/tests/functional/test_swiftclient.py
@@ -108,6 +108,7 @@ class TestFunctional(unittest.TestCase):
self.conn.delete_container(container)
except swiftclient.ClientException:
pass
+ self.conn.close()
def _check_account_headers(self, headers):
headers_to_check = [
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index f114774..62875a5 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -2532,6 +2532,9 @@ class TestConnection(MockHttpTest):
def read(self, *args, **kwargs):
return ''
+ def close(self):
+ pass
+
def local_http_connection(url, proxy=None, cacert=None,
insecure=False, cert=None, cert_key=None,
ssl_compression=True, timeout=None):
@@ -2901,6 +2904,9 @@ class TestCloseConnection(MockHttpTest):
self.assertIsNone(conn.http_conn)
conn.close()
self.assertIsNone(conn.http_conn)
+ # Can re-close
+ conn.close()
+ self.assertIsNone(conn.http_conn)
def test_close_ok(self):
url = 'http://www.test.com'
@@ -2911,7 +2917,7 @@ class TestCloseConnection(MockHttpTest):
self.assertEqual(len(conn.http_conn), 2)
http_conn_obj = conn.http_conn[1]
self.assertIsInstance(http_conn_obj, c.HTTPConnection)
- self.assertFalse(hasattr(http_conn_obj, 'close'))
+ self.assertTrue(hasattr(http_conn_obj, 'close'))
conn.close()
diff --git a/tests/unit/utils.py b/tests/unit/utils.py
index aab3b59..8081501 100644
--- a/tests/unit/utils.py
+++ b/tests/unit/utils.py
@@ -78,6 +78,10 @@ class StubResponse(object):
self.body = body
self.headers = headers or {}
+ def __repr__(self):
+ return '%s(%r, %r, %r)' % (self.__class__.__name__, self.status,
+ self.body, self.headers)
+
def fake_http_connect(*code_iter, **kwargs):
"""
@@ -102,7 +106,6 @@ def fake_http_connect(*code_iter, **kwargs):
self.etag = etag
self.content = self.body = body
self.timestamp = timestamp
- self._is_closed = True
self.headers = headers or {}
self.request = None
@@ -162,6 +165,9 @@ def fake_http_connect(*code_iter, **kwargs):
def getheader(self, name, default=None):
return dict(self.getheaders()).get(name.lower(), default)
+ def close(self):
+ pass
+
timestamps_iter = iter(kwargs.get('timestamps') or ['1'] * len(code_iter))
etag_iter = iter(kwargs.get('etags') or [None] * len(code_iter))
x = kwargs.get('missing_container', [False] * len(code_iter))
@@ -228,7 +234,8 @@ class MockHttpTest(unittest.TestCase):
parsed, _conn = _orig_http_connection(url, proxy=proxy)
class RequestsWrapper(object):
- pass
+ def close(self):
+ pass
conn = RequestsWrapper()
def request(method, path, *args, **kwargs):