1
- import asyncio
2
1
import contextlib
3
2
import datetime
4
3
import threading
11
10
from pytest_django .fixtures import SettingsWrapper
12
11
from pytest_mock import MockerFixture
13
12
13
+ import anyio
14
+
14
15
from django .core .cache import caches
15
16
from django .core .cache .backends .base import DEFAULT_TIMEOUT
16
17
from django .test import override_settings
@@ -73,15 +74,15 @@ async def test_setnx_timeout(self, cache: AsyncValkeyCache):
73
74
# test that timeout still works for nx=True
74
75
res = await cache .aset ("test_key_nx" , 1 , timeout = 2 , nx = True )
75
76
assert res is True
76
- await asyncio .sleep (3 )
77
+ await anyio .sleep (3 )
77
78
res = await cache .aget ("test_key_nx" )
78
79
assert res is None
79
80
80
81
# test that timeout will not affect key, if it was there
81
82
await cache .aset ("test_key_nx" , 1 )
82
83
res = await cache .aset ("test_key_nx" , 2 , timeout = 2 , nx = True )
83
84
assert res is None
84
- await asyncio .sleep (3 )
85
+ await anyio .sleep (3 )
85
86
res = await cache .aget ("test_key_nx" )
86
87
assert res == 1
87
88
@@ -152,7 +153,7 @@ async def test_save_float(self, cache: AsyncValkeyCache):
152
153
153
154
async def test_timeout (self , cache : AsyncValkeyCache ):
154
155
await cache .aset ("test_key" , 222 , timeout = 3 )
155
- await asyncio .sleep (4 )
156
+ await anyio .sleep (4 )
156
157
157
158
res = await cache .aget ("test_key" )
158
159
assert res is None
@@ -171,7 +172,7 @@ async def test_timeout_parameter_as_positional_argument(
171
172
172
173
await cache .aset ("test_key" , 222 , 1 )
173
174
res1 = await cache .aget ("test_key" )
174
- await asyncio .sleep (2 )
175
+ await anyio .sleep (2 )
175
176
res2 = await cache .aget ("test_key" )
176
177
assert res1 == 222
177
178
assert res2 is None
@@ -732,7 +733,7 @@ async def test_lock_released_by_thread(self, cache: AsyncValkeyCache):
732
733
async def release_lock (lock_ ):
733
734
await lock_ .release ()
734
735
735
- t = threading .Thread (target = asyncio .run , args = [release_lock ( lock ) ])
736
+ t = threading .Thread (target = anyio .run , args = [release_lock , lock ])
736
737
t .start ()
737
738
t .join ()
738
739
@@ -802,7 +803,7 @@ async def test_touch_positive_timeout(self, cache: AsyncValkeyCache):
802
803
803
804
assert await cache .atouch ("test_key" , 2 ) is True
804
805
assert await cache .aget ("test_key" ) == 222
805
- await asyncio .sleep (3 )
806
+ await anyio .sleep (3 )
806
807
assert await cache .aget ("test_key" ) is None
807
808
808
809
async def test_touch_negative_timeout (self , cache : AsyncValkeyCache ):
@@ -820,7 +821,7 @@ async def test_touch_forever(self, cache: AsyncValkeyCache):
820
821
result = await cache .atouch ("test_key" , None )
821
822
assert result is True
822
823
assert await cache .attl ("test_key" ) is None
823
- await asyncio .sleep (2 )
824
+ await anyio .sleep (2 )
824
825
assert await cache .aget ("test_key" ) == "foo"
825
826
826
827
async def test_touch_forever_nonexistent (self , cache : AsyncValkeyCache ):
@@ -831,7 +832,7 @@ async def test_touch_default_timeout(self, cache: AsyncValkeyCache):
831
832
await cache .aset ("test_key" , "foo" , timeout = 1 )
832
833
result = await cache .atouch ("test_key" )
833
834
assert result is True
834
- await asyncio .sleep (2 )
835
+ await anyio .sleep (2 )
835
836
assert await cache .aget ("test_key" ) == "foo"
836
837
837
838
async def test_clear (self , cache : AsyncValkeyCache ):
0 commit comments