import asyncio import os import pytest from app.config import get_settings from app.maintenance import acquire, release @pytest.mark.skipif(os.name == "nt", reason="Production shared flock semantics are POSIX") def test_gc_excludes_active_writers(tmp_path, monkeypatch): monkeypatch.setenv("DATA_DIR", str(tmp_path)) get_settings.cache_clear() async def check(): writer = acquire() gc = asyncio.create_task(asyncio.to_thread(acquire, True)) try: with pytest.raises(asyncio.TimeoutError): await asyncio.wait_for(asyncio.shield(gc), .1) finally: release(writer) maintenance = await asyncio.wait_for(gc, 3) release(maintenance) try: asyncio.run(check()) finally: get_settings.cache_clear()