summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-02-06 17:59:20 -0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-11 10:12:53 +0100
commit7540b7eb318b552a4324adccf5d64d39fad2ee12 (patch)
treedb763bbe71a05640e98e830eec9b4a068c220755 /tests
parentdc0dfd1dacfb26a3e7bcbe7aaf7658282cae3b54 (diff)
[3.0.x] Fixed #31253 -- Fixed data loss possibility when using caching from async code.
Case missed in a415ce70bef6d91036b00dd2c8544aed7aeeaaed. Backport of e3f6e18513224c8ad081e5a19da641f49b0b43da from master
Diffstat (limited to 'tests')
-rw-r--r--tests/async/tests.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/async/tests.py b/tests/async/tests.py
index f42e549075..86ed504c57 100644
--- a/tests/async/tests.py
+++ b/tests/async/tests.py
@@ -4,6 +4,7 @@ from unittest import mock, skipIf
from asgiref.sync import async_to_sync
+from django.core.cache import DEFAULT_CACHE_ALIAS, caches
from django.core.exceptions import SynchronousOnlyOperation
from django.test import SimpleTestCase
from django.utils.asyncio import async_unsafe
@@ -12,6 +13,18 @@ from .models import SimpleModel
@skipIf(sys.platform == 'win32' and (3, 8, 0) < sys.version_info < (3, 8, 1), 'https://bugs.python.org/issue38563')
+class CacheTest(SimpleTestCase):
+ def test_caches_local(self):
+ @async_to_sync
+ async def async_cache():
+ return caches[DEFAULT_CACHE_ALIAS]
+
+ cache_1 = async_cache()
+ cache_2 = async_cache()
+ self.assertIs(cache_1, cache_2)
+
+
+@skipIf(sys.platform == 'win32' and (3, 8, 0) < sys.version_info < (3, 8, 1), 'https://bugs.python.org/issue38563')
class DatabaseConnectionTest(SimpleTestCase):
"""A database connection cannot be used in an async context."""
@async_to_sync