Skip to content

Commit 5b89e4e

Browse files
GWealecopybara-github
authored andcommitted
test: route unit-test threads through the platform thread helper
Spawn the threads in these concurrency tests via google.adk.platform.thread.create_thread instead of constructing threading.Thread directly. Behavior is unchanged: create_thread returns a real OS thread, and the tests still use threading.Event/Barrier for coordination. Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 951583146
1 parent 509be09 commit 5b89e4e

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

tests/unittests/memory/test_in_memory_memory_service.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from google.adk.events.event import Event
1919
from google.adk.memory.in_memory_memory_service import InMemoryMemoryService
20+
from google.adk.platform import thread as platform_thread
2021
from google.adk.sessions.session import Session
2122
from google.genai import types
2223
import pytest
@@ -438,9 +439,9 @@ def reader():
438439
loop.close()
439440

440441
threads = [
441-
threading.Thread(target=writer),
442-
threading.Thread(target=reader),
443-
threading.Thread(target=reader),
442+
platform_thread.create_thread(writer),
443+
platform_thread.create_thread(reader),
444+
platform_thread.create_thread(reader),
444445
]
445446
for thread in threads:
446447
thread.start()

tests/unittests/plugins/test_bigquery_agent_analytics_plugin.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from google.adk.events import event_actions as event_actions_lib
3232
from google.adk.models import llm_request as llm_request_lib
3333
from google.adk.models import llm_response as llm_response_lib
34+
from google.adk.platform import thread as platform_thread
3435
from google.adk.plugins import bigquery_agent_analytics_plugin
3536
from google.adk.plugins import plugin_manager as plugin_manager_lib
3637
from google.adk.sessions import base_session_service as base_session_service_lib
@@ -10357,7 +10358,9 @@ def run_in_fresh_loop():
1035710358
except BaseException as e: # noqa: BLE001 - collecting for assertion
1035810359
errors.append(e)
1035910360

10360-
threads = [threading.Thread(target=run_in_fresh_loop) for _ in range(2)]
10361+
threads = [
10362+
platform_thread.create_thread(run_in_fresh_loop) for _ in range(2)
10363+
]
1036110364
for t in threads:
1036210365
t.start()
1036310366
for t in threads:
@@ -10487,7 +10490,9 @@ def run_in_fresh_loop():
1048710490
except BaseException as e: # noqa: BLE001
1048810491
errors.append(e)
1048910492

10490-
threads = [threading.Thread(target=run_in_fresh_loop) for _ in range(2)]
10493+
threads = [
10494+
platform_thread.create_thread(run_in_fresh_loop) for _ in range(2)
10495+
]
1049110496
for t in threads:
1049210497
t.start()
1049310498
# Deterministic rendezvous: hold the owner inside setup until BOTH
@@ -10534,7 +10539,9 @@ def run_in_fresh_loop():
1053410539
except BaseException as e: # noqa: BLE001
1053510540
errors.append(e)
1053610541

10537-
threads = [threading.Thread(target=run_in_fresh_loop) for _ in range(2)]
10542+
threads = [
10543+
platform_thread.create_thread(run_in_fresh_loop) for _ in range(2)
10544+
]
1053810545
for t in threads:
1053910546
t.start()
1054010547
entered.wait(timeout=5)

0 commit comments

Comments
 (0)