Add connection release test
This patch adds a small test to ensure a connection is released after all chunks have been consumed. It's a follow up to commit 8756591b and added to ensure there will be no regression in the future (this test fails also with that patch not applied). Change-Id: I6a6fcd26879eb2070f418c8770a395ff6c30aa51
This commit is contained in:
parent
ec3e2ab3a0
commit
7f2ee7322b
@ -75,6 +75,7 @@ class MockHttpResponse(object):
|
|||||||
self.headers = {'etag': '"%s"' % EMPTY_ETAG}
|
self.headers = {'etag': '"%s"' % EMPTY_ETAG}
|
||||||
if headers:
|
if headers:
|
||||||
self.headers.update(headers)
|
self.headers.update(headers)
|
||||||
|
self.closed = False
|
||||||
|
|
||||||
class Raw(object):
|
class Raw(object):
|
||||||
def __init__(self, headers):
|
def __init__(self, headers):
|
||||||
@ -92,7 +93,7 @@ class MockHttpResponse(object):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
self.closed = True
|
||||||
|
|
||||||
def getheader(self, name, default):
|
def getheader(self, name, default):
|
||||||
return self.headers.get(name, default)
|
return self.headers.get(name, default)
|
||||||
@ -1145,6 +1146,17 @@ class TestHTTPConnection(MockHttpTest):
|
|||||||
conn = c.http_connection(u'http://www.test.com/', insecure=True)
|
conn = c.http_connection(u'http://www.test.com/', insecure=True)
|
||||||
self.assertEqual(conn[1].requests_args['verify'], False)
|
self.assertEqual(conn[1].requests_args['verify'], False)
|
||||||
|
|
||||||
|
def test_response_connection_released(self):
|
||||||
|
_parsed_url, conn = c.http_connection(u'http://www.test.com/')
|
||||||
|
conn.resp = MockHttpResponse()
|
||||||
|
conn.resp.raw = mock.Mock()
|
||||||
|
conn.resp.raw.read.side_effect = ["Chunk", ""]
|
||||||
|
resp = conn.getresponse()
|
||||||
|
self.assertFalse(resp.closed)
|
||||||
|
self.assertEqual("Chunk", resp.read())
|
||||||
|
self.assertFalse(resp.read())
|
||||||
|
self.assertTrue(resp.closed)
|
||||||
|
|
||||||
|
|
||||||
class TestConnection(MockHttpTest):
|
class TestConnection(MockHttpTest):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user