wip test stabalization is a mess still

This commit is contained in:
2026-03-03 23:53:53 -05:00
parent c0a8777204
commit 3203891b79
17 changed files with 263 additions and 422 deletions

View File

@@ -50,27 +50,19 @@ def app_instance() -> Generator[App, None, None]:
):
app = App()
yield app
# Cleanup: Ensure asyncio loop is stopped and tasks are cancelled
if hasattr(app, '_loop'):
# 1. Stop the loop thread-safely first
if app._loop.is_running():
app._loop.call_soon_threadsafe(app._loop.stop)
# Cleanup: Ensure background threads and asyncio loop are stopped
app.shutdown()
if hasattr(app, '_loop') and not app._loop.is_closed():
tasks = [t for t in asyncio.all_tasks(app._loop) if not t.done()]
if tasks:
# Cancel tasks so they can be gathered
for task in tasks:
task.cancel()
app._loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
# 2. Join the loop thread
if hasattr(app, '_loop_thread') and app._loop_thread.is_alive():
app._loop_thread.join(timeout=2.0)
# 3. Check for pending tasks after thread is joined
if not app._loop.is_closed():
tasks = [t for t in asyncio.all_tasks(app._loop) if not t.done()]
if tasks:
# Cancel tasks so they can be gathered
for task in tasks:
task.cancel()
app._loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
# 4. Finally close the loop
app._loop.close()
# 4. Finally close the loop
app._loop.close()
@pytest.fixture
def mock_app(app_instance: App) -> App: