|
21 | 21 | DEFAULT_CACHE_ALIAS, CacheKeyWarning, cache, caches,
|
22 | 22 | )
|
23 | 23 | from django.core.cache.utils import make_template_fragment_key
|
24 |
| -from django.db import connection, connections |
| 24 | +from django.db import close_old_connections, connection, connections |
25 | 25 | from django.http import (
|
26 | 26 | HttpRequest, HttpResponse, HttpResponseNotModified, StreamingHttpResponse,
|
27 | 27 | )
|
@@ -1248,9 +1248,13 @@ def test_memcached_deletes_key_on_failed_set(self):
|
1248 | 1248 | def test_close(self):
|
1249 | 1249 | # For clients that don't manage their connections properly, the
|
1250 | 1250 | # connection is closed when the request is complete.
|
1251 |
| - with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect: |
1252 |
| - signals.request_finished.send(self.__class__) |
1253 |
| - self.assertIs(mock_disconnect.called, self.should_disconnect_on_close) |
| 1251 | + signals.request_finished.disconnect(close_old_connections) |
| 1252 | + try: |
| 1253 | + with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect: |
| 1254 | + signals.request_finished.send(self.__class__) |
| 1255 | + self.assertIs(mock_disconnect.called, self.should_disconnect_on_close) |
| 1256 | + finally: |
| 1257 | + signals.request_finished.connect(close_old_connections) |
1254 | 1258 |
|
1255 | 1259 |
|
1256 | 1260 | @unittest.skipUnless(MemcachedCache_params, "MemcachedCache backend not configured")
|
|
0 commit comments