mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: Improve asyncio loop handling and test cleanup
This CL enhances asyncio event loop management and test isolation. - **BigQuery Analytics Plugin:** Ensure the asyncio event loop is consistently closed within the BigQuery analytics plugin. This prevents potential resource leaks. Add checks to handle potential deadlocks in Python 3.13+ when creating loops during interpreter shutdown. - **Test Thread Pool Cleanup:** Introduce a pytest fixture (`cleanup_thread_pools`) to automatically shut down and clear all tool-related thread pools after each test run in `test_functions_thread_pool.py`. This improves test isolation and prevents order-dependent test failures. - **Streaming Test Loop Restoration:** Refactor event loop handling in `test_streaming.py`. A new `_run_with_loop` method is introduced in the custom test runners to create a temporary event loop for each test execution, run the coroutine, and crucially, restore the original event loop afterwards. This prevents tests from interfering with each other's loop state. - **Resource Closure:** Ensure services are closed properly in tests by adding `await service.close()` in `test_service_factory.py` and using `async with session_service` in `test_session_service.py`. PiperOrigin-RevId: 863305565
This commit is contained in:
committed by
Copybara-Service
parent
585ebfdac7
commit
00aba2d884
@@ -32,6 +32,17 @@ import pytest
|
||||
from ... import testing_utils
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def cleanup_thread_pools():
|
||||
yield
|
||||
from google.adk.flows.llm_flows import functions
|
||||
|
||||
# Shutdown all pools
|
||||
for pool in functions._TOOL_THREAD_POOLS.values():
|
||||
pool.shutdown(wait=False)
|
||||
functions._TOOL_THREAD_POOLS.clear()
|
||||
|
||||
|
||||
class TestIsSyncTool:
|
||||
"""Tests for the _is_sync_tool helper function."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user