From 7f2ee7322b3f16fdd2c848be07c67107f4e065dd Mon Sep 17 00:00:00 2001
From: Christian Schwede <christian.schwede@enovance.com>
Date: Wed, 25 Feb 2015 10:58:27 +0000
Subject: [PATCH] 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
---
 tests/unit/test_swiftclient.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index ae460999..1cfe2044 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -75,6 +75,7 @@ class MockHttpResponse(object):
         self.headers = {'etag': '"%s"' % EMPTY_ETAG}
         if headers:
             self.headers.update(headers)
+        self.closed = False
 
         class Raw(object):
             def __init__(self, headers):
@@ -92,7 +93,7 @@ class MockHttpResponse(object):
         return ""
 
     def close(self):
-        pass
+        self.closed = True
 
     def getheader(self, 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)
         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):