Skip to content

Commit f18a9bb

Browse files
committed
🧪 test(async): exercise both singleton backends
1 parent 47b6e4b commit f18a9bb

2 files changed

Lines changed: 21 additions & 24 deletions

File tree

‎tests/test_async_read_write.py‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import sqlite3
2727

28-
from filelock import AsyncReadWriteLock, AsyncSoftReadWriteLock, ReadWriteLock, Timeout
28+
from filelock import AsyncReadWriteLock, ReadWriteLock, Timeout
2929

3030
if TYPE_CHECKING:
3131
import functools
@@ -1072,29 +1072,6 @@ async def test_async_close_waits_out_an_acquire_in_flight_even_when_canceled(loc
10721072
holder.close()
10731073

10741074

1075-
@pytest.mark.parametrize(
1076-
"lock_type", [pytest.param(AsyncReadWriteLock, id="sqlite"), pytest.param(AsyncSoftReadWriteLock, id="soft")]
1077-
)
1078-
@pytest.mark.asyncio
1079-
async def test_singleton_close_returns_while_another_wrapper_enters(
1080-
lock_file: str, lock_type: type[AsyncReadWriteLock | AsyncSoftReadWriteLock]
1081-
) -> None:
1082-
holder = lock_type(lock_file, is_singleton=False)
1083-
waiting, idle = lock_type(lock_file), lock_type(lock_file)
1084-
async with holder.write_lock():
1085-
acquiring = asyncio.create_task(waiting.acquire_write())
1086-
await asyncio.sleep(0)
1087-
closing = asyncio.create_task(idle.close())
1088-
done, _ = await asyncio.wait({closing}, timeout=2)
1089-
try:
1090-
await acquiring
1091-
await closing
1092-
assert closing in done
1093-
finally:
1094-
await waiting.close()
1095-
await holder.close()
1096-
1097-
10981075
@pytest.mark.asyncio
10991076
@pytest.mark.parametrize("is_singleton", [pytest.param(False, id="owned"), pytest.param(True, id="singleton")])
11001077
async def test_close_interrupts_backend_wait_while_peer_holds(lock_file: str, *, is_singleton: bool) -> None:

‎tests/test_async_read_write_cancel_wait.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,23 @@ def write_once() -> None:
160160
holder.release()
161161
await asyncio.to_thread(waiting.join, _HOLD * 2)
162162
await lock.close()
163+
164+
165+
@_FAMILIES
166+
@pytest.mark.asyncio
167+
async def test_singleton_close_returns_while_another_wrapper_enters(tmp_path: Path, make: _Make) -> None:
168+
holder, waiting = make(tmp_path, is_singleton=False)
169+
shared, idle = make(tmp_path, is_singleton=True)
170+
with holder.write_lock():
171+
acquiring = asyncio.create_task(waiting.acquire_write())
172+
await asyncio.sleep(0)
173+
closing = asyncio.create_task(idle.close())
174+
done, _ = await asyncio.wait({closing}, timeout=2)
175+
try:
176+
await acquiring
177+
await closing
178+
assert closing in done
179+
finally:
180+
await waiting.close()
181+
shared.close()
182+
holder.close()

0 commit comments

Comments
 (0)