Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(google-adk): await legacy Runner nested finalizers
  • Loading branch information
jabrailkhalil committed Oct 18, 2026
commit 1faa895a4ef407c985eed99cfb360a5c294a2e86
10 changes: 10 additions & 0 deletions python/tests/test_google_adk_stream_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Offline integration with ADK's actual Runner and BaseAgent methods."""

import asyncio
from typing import ClassVar

import pytest
Expand All @@ -21,6 +22,7 @@
@pytest.mark.parametrize("close_early", [False, True])
async def test_runner_stream_lifecycle(close_early):
cleaned = []
cleanup_finished = asyncio.Event()

class StreamingAgent(BaseAgent):
outputs: ClassVar[list[Event]] = [
Expand All @@ -43,6 +45,7 @@ async def _run_async_impl(self, ctx):
yield result
finally:
cleaned.append(True)
cleanup_finished.set()

provider = TracerProvider()
exporter = InMemorySpanExporter()
Expand All @@ -69,6 +72,13 @@ async def _run_async_impl(self, ctx):
assert context_api.get_current() is before
if close_early:
await stream.aclose()
assert any(
span.name == "invocation [stream-test]"
for span in exporter.get_finished_spans()
)
# Older ADK runners rely on async-generator finalization for
# nested streams rather than closing them before returning.
await asyncio.wait_for(cleanup_finished.wait(), timeout=2)
else:
remaining = [result async for result in stream]
assert remaining[-1].content.parts[0].text == "complete"
Expand Down