From 4dd8a79c4e1ee9bc0e7490c4da838572a409983d Mon Sep 17 00:00:00 2001 From: Richard Lundeen Date: Mon, 19 Oct 2026 16:48:49 -0700 Subject: [PATCH] TEST: Join SQLite cleanup workers before leak checks Run the fixture GC regression in an isolated asyncio.Runner so executor work items release bound disposal methods before collection. Keep the weak-reference assertion and real cleanup checks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac1d8921-cfc7-4a1c-bf94-cc7c7bf51566 --- tests/unit/memory/test_sqlite_fixtures.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/unit/memory/test_sqlite_fixtures.py b/tests/unit/memory/test_sqlite_fixtures.py index 3e84ec5f0c..0f67072a1f 100644 --- a/tests/unit/memory/test_sqlite_fixtures.py +++ b/tests/unit/memory/test_sqlite_fixtures.py @@ -242,12 +242,16 @@ async def test_sqlite_instance_cleans_up_on_failure( _assert_closed(sqlite_connections) -async def test_sqlite_instance_does_not_retain_process_exit_cleanup(sqlite_template: sqlite3.Connection) -> None: - async with _sqlite_instance(sqlite_template=sqlite_template) as memory: - assert memory.cleanup.__func__ is MemoryInterface.cleanup - assert "cleanup" not in memory.__dict__ - memory_reference = weakref.ref(memory) - del memory +def test_sqlite_instance_does_not_retain_process_exit_cleanup(sqlite_template: sqlite3.Connection) -> None: + async def release_memory_async() -> weakref.ReferenceType[SQLiteMemory]: + async with _sqlite_instance(sqlite_template=sqlite_template) as memory: + assert memory.cleanup.__func__ is MemoryInterface.cleanup + assert "cleanup" not in memory.__dict__ + return weakref.ref(memory) + + # Disposal's future can finish before its worker releases the bound method. + with asyncio.Runner() as runner: + memory_reference = runner.run(release_memory_async()) gc.collect() assert memory_reference() is None