Skip to content

Commit bfd5344

Browse files
committed
use anyio tools in tests
1 parent 7c6c019 commit bfd5344

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/tests_async/test_backend.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import contextlib
32
import datetime
43
import threading
@@ -11,6 +10,8 @@
1110
from pytest_django.fixtures import SettingsWrapper
1211
from pytest_mock import MockerFixture
1312

13+
import anyio
14+
1415
from django.core.cache import caches
1516
from django.core.cache.backends.base import DEFAULT_TIMEOUT
1617
from django.test import override_settings
@@ -73,15 +74,15 @@ async def test_setnx_timeout(self, cache: AsyncValkeyCache):
7374
# test that timeout still works for nx=True
7475
res = await cache.aset("test_key_nx", 1, timeout=2, nx=True)
7576
assert res is True
76-
await asyncio.sleep(3)
77+
await anyio.sleep(3)
7778
res = await cache.aget("test_key_nx")
7879
assert res is None
7980

8081
# test that timeout will not affect key, if it was there
8182
await cache.aset("test_key_nx", 1)
8283
res = await cache.aset("test_key_nx", 2, timeout=2, nx=True)
8384
assert res is None
84-
await asyncio.sleep(3)
85+
await anyio.sleep(3)
8586
res = await cache.aget("test_key_nx")
8687
assert res == 1
8788

@@ -152,7 +153,7 @@ async def test_save_float(self, cache: AsyncValkeyCache):
152153

153154
async def test_timeout(self, cache: AsyncValkeyCache):
154155
await cache.aset("test_key", 222, timeout=3)
155-
await asyncio.sleep(4)
156+
await anyio.sleep(4)
156157

157158
res = await cache.aget("test_key")
158159
assert res is None
@@ -171,7 +172,7 @@ async def test_timeout_parameter_as_positional_argument(
171172

172173
await cache.aset("test_key", 222, 1)
173174
res1 = await cache.aget("test_key")
174-
await asyncio.sleep(2)
175+
await anyio.sleep(2)
175176
res2 = await cache.aget("test_key")
176177
assert res1 == 222
177178
assert res2 is None
@@ -732,7 +733,7 @@ async def test_lock_released_by_thread(self, cache: AsyncValkeyCache):
732733
async def release_lock(lock_):
733734
await lock_.release()
734735

735-
t = threading.Thread(target=asyncio.run, args=[release_lock(lock)])
736+
t = threading.Thread(target=anyio.run, args=[release_lock, lock])
736737
t.start()
737738
t.join()
738739

@@ -802,7 +803,7 @@ async def test_touch_positive_timeout(self, cache: AsyncValkeyCache):
802803

803804
assert await cache.atouch("test_key", 2) is True
804805
assert await cache.aget("test_key") == 222
805-
await asyncio.sleep(3)
806+
await anyio.sleep(3)
806807
assert await cache.aget("test_key") is None
807808

808809
async def test_touch_negative_timeout(self, cache: AsyncValkeyCache):
@@ -820,7 +821,7 @@ async def test_touch_forever(self, cache: AsyncValkeyCache):
820821
result = await cache.atouch("test_key", None)
821822
assert result is True
822823
assert await cache.attl("test_key") is None
823-
await asyncio.sleep(2)
824+
await anyio.sleep(2)
824825
assert await cache.aget("test_key") == "foo"
825826

826827
async def test_touch_forever_nonexistent(self, cache: AsyncValkeyCache):
@@ -831,7 +832,7 @@ async def test_touch_default_timeout(self, cache: AsyncValkeyCache):
831832
await cache.aset("test_key", "foo", timeout=1)
832833
result = await cache.atouch("test_key")
833834
assert result is True
834-
await asyncio.sleep(2)
835+
await anyio.sleep(2)
835836
assert await cache.aget("test_key") == "foo"
836837

837838
async def test_clear(self, cache: AsyncValkeyCache):

0 commit comments

Comments
 (0)