mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed #32831 -– Allowed cache tests to be retried via a new "retry" decorator.
This commit is contained in:
parent
aa52930687
commit
957c54d945
25
tests/cache/tests.py
vendored
25
tests/cache/tests.py
vendored
@ -11,6 +11,7 @@ import tempfile
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
from functools import wraps
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import mock, skipIf
|
from unittest import mock, skipIf
|
||||||
|
|
||||||
@ -89,6 +90,25 @@ KEY_ERRORS_WITH_MEMCACHED_MSG = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def retry(retries=3, delay=1):
|
||||||
|
def decorator(func):
|
||||||
|
@wraps(func)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
attempts = 0
|
||||||
|
while attempts < retries:
|
||||||
|
try:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
except AssertionError:
|
||||||
|
attempts += 1
|
||||||
|
if attempts >= retries:
|
||||||
|
raise
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
CACHES={
|
CACHES={
|
||||||
"default": {
|
"default": {
|
||||||
@ -489,6 +509,7 @@ class BaseCacheTests:
|
|||||||
self.assertEqual(cache.get("expire2"), "newvalue")
|
self.assertEqual(cache.get("expire2"), "newvalue")
|
||||||
self.assertIs(cache.has_key("expire3"), False)
|
self.assertIs(cache.has_key("expire3"), False)
|
||||||
|
|
||||||
|
@retry()
|
||||||
def test_touch(self):
|
def test_touch(self):
|
||||||
# cache.touch() updates the timeout.
|
# cache.touch() updates the timeout.
|
||||||
cache.set("expire1", "very quickly", timeout=1)
|
cache.set("expire1", "very quickly", timeout=1)
|
||||||
@ -616,6 +637,7 @@ class BaseCacheTests:
|
|||||||
self.assertEqual(cache.get("key3"), "sausage")
|
self.assertEqual(cache.get("key3"), "sausage")
|
||||||
self.assertEqual(cache.get("key4"), "lobster bisque")
|
self.assertEqual(cache.get("key4"), "lobster bisque")
|
||||||
|
|
||||||
|
@retry()
|
||||||
def test_forever_timeout(self):
|
def test_forever_timeout(self):
|
||||||
"""
|
"""
|
||||||
Passing in None into timeout results in a value that is cached forever
|
Passing in None into timeout results in a value that is cached forever
|
||||||
@ -1397,6 +1419,7 @@ class LocMemCacheTests(BaseCacheTests, TestCase):
|
|||||||
self.assertEqual(cache.decr(key), 1)
|
self.assertEqual(cache.decr(key), 1)
|
||||||
self.assertEqual(expire, cache._expire_info[_key])
|
self.assertEqual(expire, cache._expire_info[_key])
|
||||||
|
|
||||||
|
@retry()
|
||||||
@limit_locmem_entries
|
@limit_locmem_entries
|
||||||
def test_lru_get(self):
|
def test_lru_get(self):
|
||||||
"""get() moves cache keys."""
|
"""get() moves cache keys."""
|
||||||
@ -1424,6 +1447,7 @@ class LocMemCacheTests(BaseCacheTests, TestCase):
|
|||||||
for key in range(3):
|
for key in range(3):
|
||||||
self.assertIsNone(cache.get(key))
|
self.assertIsNone(cache.get(key))
|
||||||
|
|
||||||
|
@retry()
|
||||||
@limit_locmem_entries
|
@limit_locmem_entries
|
||||||
def test_lru_incr(self):
|
def test_lru_incr(self):
|
||||||
"""incr() moves cache keys."""
|
"""incr() moves cache keys."""
|
||||||
@ -2674,6 +2698,7 @@ class CacheMiddlewareTest(SimpleTestCase):
|
|||||||
response = other_with_prefix_view(request, "16")
|
response = other_with_prefix_view(request, "16")
|
||||||
self.assertEqual(response.content, b"Hello World 16")
|
self.assertEqual(response.content, b"Hello World 16")
|
||||||
|
|
||||||
|
@retry()
|
||||||
def test_cache_page_timeout(self):
|
def test_cache_page_timeout(self):
|
||||||
# Page timeout takes precedence over the "max-age" section of the
|
# Page timeout takes precedence over the "max-age" section of the
|
||||||
# "Cache-Control".
|
# "Cache-Control".
|
||||||
|
Loading…
Reference in New Issue
Block a user