Refs #5133 -- Isolated test_close() cache test.

This commit is contained in:
Tim Graham 2016-09-14 14:25:09 -04:00
parent 3c447b108a
commit 82f8996785
1 changed files with 8 additions and 4 deletions

12
tests/cache/tests.py vendored
View File

@ -21,7 +21,7 @@ from django.core.cache import (
DEFAULT_CACHE_ALIAS, CacheKeyWarning, cache, caches, DEFAULT_CACHE_ALIAS, CacheKeyWarning, cache, caches,
) )
from django.core.cache.utils import make_template_fragment_key from django.core.cache.utils import make_template_fragment_key
from django.db import connection, connections from django.db import close_old_connections, connection, connections
from django.http import ( from django.http import (
HttpRequest, HttpResponse, HttpResponseNotModified, StreamingHttpResponse, HttpRequest, HttpResponse, HttpResponseNotModified, StreamingHttpResponse,
) )
@ -1248,9 +1248,13 @@ class BaseMemcachedTests(BaseCacheTests):
def test_close(self): def test_close(self):
# For clients that don't manage their connections properly, the # For clients that don't manage their connections properly, the
# connection is closed when the request is complete. # connection is closed when the request is complete.
with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect: signals.request_finished.disconnect(close_old_connections)
signals.request_finished.send(self.__class__) try:
self.assertIs(mock_disconnect.called, self.should_disconnect_on_close) with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect:
signals.request_finished.send(self.__class__)
self.assertIs(mock_disconnect.called, self.should_disconnect_on_close)
finally:
signals.request_finished.connect(close_old_connections)
@unittest.skipUnless(MemcachedCache_params, "MemcachedCache backend not configured") @unittest.skipUnless(MemcachedCache_params, "MemcachedCache backend not configured")