test: synchronize BigQuery write assertions
The BigQuery analytics plugin test relied on fixed 10ms sleeps to wait for asynchronous writes, which is not a valid completion signal and produced timing-dependent failures and leaked Queue.get coroutine warnings. This replaces the sleeps with the plugin's flush() synchronization boundary and shuts the loop-owned worker down before closing the event loop. Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 951592599
This commit is contained in:
committed by
Copybara-Service
parent
5b89e4e0a7
commit
2dc07457b0
@@ -596,7 +596,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01) # Allow background task to run
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
mock_write_client.append_rows.reset_mock()
|
||||
user_message = types.Content(parts=[types.Part(text="What is up?")])
|
||||
@@ -604,7 +604,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.on_user_message_callback(
|
||||
invocation_context=invocation_context, user_message=user_message
|
||||
)
|
||||
await asyncio.sleep(0.01) # Allow background task to run
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_not_called()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -633,11 +633,11 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.on_user_message_callback(
|
||||
invocation_context=invocation_context, user_message=user_message
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_not_called()
|
||||
bigquery_agent_analytics_plugin.TraceManager.push_span(invocation_context)
|
||||
await plugin.before_run_callback(invocation_context=invocation_context)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -680,7 +680,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01) # Allow background task to run
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
metadata = mock_write_client.append_rows.call_args.kwargs.get("metadata")
|
||||
assert metadata is not None, "append_rows must receive routing metadata"
|
||||
@@ -720,7 +720,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.on_user_message_callback(
|
||||
invocation_context=invocation_context, user_message=user_message
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -759,7 +759,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.on_user_message_callback(
|
||||
invocation_context=invocation_context, user_message=user_message
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -804,7 +804,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.on_user_message_callback(
|
||||
invocation_context=invocation_context, user_message=user_message
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -832,7 +832,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -885,7 +885,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_args={"param": "A" * 100},
|
||||
tool_context=tool_context,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -931,7 +931,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_args={"param": "A" * 100},
|
||||
tool_context=tool_context,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -980,7 +980,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_context=tool_context,
|
||||
result={"res": "A" * 100},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -1029,7 +1029,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_context=tool_context,
|
||||
result={"res": "A" * 100},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -1073,7 +1073,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_context=tool_context,
|
||||
error=ValueError("Oops"),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -1100,7 +1100,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.on_user_message_callback(
|
||||
invocation_context=invocation_context, user_message=user_message
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1151,7 +1151,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await plugin.on_user_message_callback(
|
||||
invocation_context=invocation_context, user_message=user_message
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -1201,7 +1201,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(parts=[types.Part(text="Test")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin_with_fail.flush()
|
||||
mock_logger.error.assert_called_with(
|
||||
"Failed to initialize BigQuery Plugin (attempt %d, next"
|
||||
" retry in %.0fs): %s",
|
||||
@@ -1235,7 +1235,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(parts=[types.Part(text="Test")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
# The logger is called multiple times, check that one of them is the error message
|
||||
# Or just check that it was called with the expected message at some point
|
||||
mock_logger.error.assert_any_call(
|
||||
@@ -1268,7 +1268,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(parts=[types.Part(text="Test")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
mock_logger.warning.assert_any_call(
|
||||
"BigQuery Write API returned error code %s: %s",
|
||||
10,
|
||||
@@ -1302,7 +1302,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(parts=[types.Part(text="Test")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
mock_logger.error.assert_called_with(
|
||||
"BigQuery Schema Mismatch: %s. This usually means the"
|
||||
" table schema does not match the expected schema.",
|
||||
@@ -1333,7 +1333,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_run_callback(
|
||||
invocation_context=invocation_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1352,7 +1352,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.after_run_callback(
|
||||
invocation_context=invocation_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1372,7 +1372,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_agent_callback(
|
||||
agent=mock_agent, callback_context=callback_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1392,7 +1392,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.after_agent_callback(
|
||||
agent=mock_agent, callback_context=callback_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1421,7 +1421,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1451,7 +1451,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1526,7 +1526,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1654,7 +1654,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1703,7 +1703,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1731,7 +1731,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
llm_response=llm_response,
|
||||
# latency_ms is now calculated internally via TraceManager
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1769,7 +1769,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
callback_context=callback_context,
|
||||
llm_response=llm_response,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1793,7 +1793,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_tool_callback(
|
||||
tool=mock_tool, tool_args={"param": "value"}, tool_context=tool_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1818,7 +1818,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_context=tool_context,
|
||||
result={"res": "success"},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1848,7 +1848,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_context=tool_context,
|
||||
result={"res": "success"},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
# Only TOOL_COMPLETED should be logged; STATE_DELTA is handled
|
||||
# by on_event_callback now.
|
||||
@@ -1878,7 +1878,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
# Must return None to not modify the event
|
||||
assert result is None
|
||||
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1932,7 +1932,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
callback_context,
|
||||
raw_content="test content",
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -1964,7 +1964,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
callback_context,
|
||||
raw_content="test content",
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -2025,7 +2025,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
source_event=event
|
||||
),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -2049,7 +2049,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
callback_context,
|
||||
raw_content="test content",
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -2074,7 +2074,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.on_model_error_callback(
|
||||
callback_context=callback_context, llm_request=llm_request, error=error
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -2100,7 +2100,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_context=tool_context,
|
||||
error=error,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -2358,18 +2358,22 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
# that if it were called in a thread, it would work.
|
||||
# For this test, we just ensure the plugin is accessible and started.
|
||||
loop.run_until_complete(p._ensure_started())
|
||||
return p._started, bool(p._loop_state_by_loop)
|
||||
finally:
|
||||
loop.close()
|
||||
try:
|
||||
loop.run_until_complete(p.shutdown())
|
||||
finally:
|
||||
loop.close()
|
||||
|
||||
# Run in a separate thread to simulate ThreadPoolExecutor-0_0
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
with ThreadPoolExecutor(max_workers=1) as executor:
|
||||
future = executor.submit(_run_in_thread, plugin)
|
||||
future.result() # Should not raise "no current event loop"
|
||||
assert plugin._started
|
||||
# Verify loop states are populated
|
||||
assert plugin._loop_state_by_loop
|
||||
started, had_loop_state = future.result()
|
||||
assert started
|
||||
assert had_loop_state
|
||||
assert not plugin._loop_state_by_loop
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multimodal_offloading(
|
||||
@@ -2612,7 +2616,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
# Capture the actual LLM Span ID (pushed by before_model_callback)
|
||||
llm_span_id = (
|
||||
bigquery_agent_analytics_plugin.TraceManager.get_current_span_id()
|
||||
@@ -2638,7 +2642,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
await bq_plugin_inst.after_model_callback(
|
||||
callback_context=callback_context, llm_response=llm_response
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry_resp = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -2701,7 +2705,7 @@ class TestBigQueryAgentAnalyticsPlugin:
|
||||
tool_context,
|
||||
raw_content=content,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -3239,7 +3243,7 @@ class TestSafeCallbackDecorator:
|
||||
await bq_plugin_inst.before_run_callback(
|
||||
invocation_context=invocation_context,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
mock_write_client.append_rows.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -3364,7 +3368,7 @@ class TestParserReuse:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(parts=[types.Part(text="Hello")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
# Parser should be the same instance, not a new one
|
||||
assert bq_plugin_inst.parser is parser_after_init
|
||||
@@ -3392,7 +3396,7 @@ class TestParserReuse:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(parts=[types.Part(text="Test")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
# The shared parser's constructor-time fields are untouched; identity
|
||||
# travelled through the parse() call arguments instead.
|
||||
@@ -3419,7 +3423,7 @@ class TestParserReuse:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(parts=[types.Part(text="Test")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
# Constructor should NOT have been called during _log_event
|
||||
mock_parser_cls.assert_not_called()
|
||||
|
||||
@@ -3820,7 +3824,7 @@ class TestDuplicateLabels:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -3847,7 +3851,7 @@ class TestDuplicateLabels:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -3871,7 +3875,7 @@ class TestDuplicateLabels:
|
||||
await bq_plugin_inst.before_model_callback(
|
||||
callback_context=callback_context, llm_request=llm_request
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -4446,7 +4450,7 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"project_id": "my-project"},
|
||||
tool_context=ctx_a,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# --- Subagent B: image_describer calls describe_this_image ---
|
||||
inv_ctx_b = self._make_invocation_context("image_describer", session)
|
||||
@@ -4459,7 +4463,7 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"image_uri": "gs://bucket/image.jpg"},
|
||||
tool_context=ctx_b,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -4513,14 +4517,14 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"project_id": "proj"},
|
||||
tool_context=ctx_1,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
await plugin.after_tool_callback(
|
||||
tool=tool_1,
|
||||
tool_args={"project_id": "proj"},
|
||||
tool_context=ctx_1,
|
||||
result={"datasets": ["ds1", "ds2"]},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# --- Turn 2: query_analyst calls execute_sql ---
|
||||
inv_ctx_2 = self._make_invocation_context(
|
||||
@@ -4535,14 +4539,14 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"sql": "SELECT * FROM t"},
|
||||
tool_context=ctx_2,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
await plugin.after_tool_callback(
|
||||
tool=tool_2,
|
||||
tool_args={"sql": "SELECT * FROM t"},
|
||||
tool_context=ctx_2,
|
||||
result={"rows": [{"col": "val"}]},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -4607,7 +4611,7 @@ class TestMultiSubagentToolLogging:
|
||||
await plugin.before_agent_callback(
|
||||
agent=mock_agent, callback_context=cb_ctx
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# 2. LLM_REQUEST (agent decides to call a tool)
|
||||
llm_req = llm_request_lib.LlmRequest(
|
||||
@@ -4619,7 +4623,7 @@ class TestMultiSubagentToolLogging:
|
||||
await plugin.before_model_callback(
|
||||
callback_context=cb_ctx, llm_request=llm_req
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# 3. LLM_RESPONSE (function call)
|
||||
llm_resp = llm_response_lib.LlmResponse(
|
||||
@@ -4637,7 +4641,7 @@ class TestMultiSubagentToolLogging:
|
||||
await plugin.after_model_callback(
|
||||
callback_context=cb_ctx, llm_response=llm_resp
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# 4. TOOL_STARTING
|
||||
bigquery_agent_analytics_plugin.TraceManager.push_span(tool_ctx, "tool")
|
||||
@@ -4646,7 +4650,7 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"table": "events"},
|
||||
tool_context=tool_ctx,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# 5. TOOL_COMPLETED
|
||||
await plugin.after_tool_callback(
|
||||
@@ -4655,13 +4659,13 @@ class TestMultiSubagentToolLogging:
|
||||
tool_context=tool_ctx,
|
||||
result={"schema": [{"name": "id", "type": "INT64"}]},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# 6. AGENT_COMPLETED
|
||||
await plugin.after_agent_callback(
|
||||
agent=mock_agent, callback_context=cb_ctx
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -4726,7 +4730,7 @@ class TestMultiSubagentToolLogging:
|
||||
tool_context=tool_ctx,
|
||||
error=RuntimeError("Table not found"),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -4775,14 +4779,14 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"dataset": "analytics"},
|
||||
tool_context=ctx_1,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
await plugin.after_tool_callback(
|
||||
tool=tool_1,
|
||||
tool_args={"dataset": "analytics"},
|
||||
tool_context=ctx_1,
|
||||
result={"tables": ["events", "metrics"]},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# Subagent 2: image_describer — full tool cycle
|
||||
inv_ctx_2 = self._make_invocation_context(
|
||||
@@ -4796,14 +4800,14 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"image_uri": "https://example.com/img.jpg"},
|
||||
tool_context=ctx_2,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
await plugin.after_tool_callback(
|
||||
tool=tool_2,
|
||||
tool_args={"image_uri": "https://example.com/img.jpg"},
|
||||
tool_context=ctx_2,
|
||||
result={"description": "A photo of scones"},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -4877,7 +4881,7 @@ class TestMultiSubagentToolLogging:
|
||||
agent=inv_ctx_t1_orch.agent,
|
||||
callback_context=cb_ctx_t1_orch,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# Orchestrator delegates to schema_explorer
|
||||
inv_ctx_t1_sub = self._make_invocation_context(
|
||||
@@ -4892,7 +4896,7 @@ class TestMultiSubagentToolLogging:
|
||||
agent=inv_ctx_t1_sub.agent,
|
||||
callback_context=cb_ctx_t1_sub,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# schema_explorer calls tool
|
||||
tool_1 = self._make_tool("list_dataset_ids")
|
||||
@@ -4904,28 +4908,28 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"project_id": "proj"},
|
||||
tool_context=tool_ctx_t1,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
await plugin.after_tool_callback(
|
||||
tool=tool_1,
|
||||
tool_args={"project_id": "proj"},
|
||||
tool_context=tool_ctx_t1,
|
||||
result={"datasets": ["ds1"]},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# schema_explorer done
|
||||
await plugin.after_agent_callback(
|
||||
agent=inv_ctx_t1_sub.agent,
|
||||
callback_context=cb_ctx_t1_sub,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# Orchestrator done
|
||||
await plugin.after_agent_callback(
|
||||
agent=inv_ctx_t1_orch.agent,
|
||||
callback_context=cb_ctx_t1_orch,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# ===== Turn 2: image_describer =====
|
||||
inv_ctx_t2_orch = self._make_invocation_context(
|
||||
@@ -4937,7 +4941,7 @@ class TestMultiSubagentToolLogging:
|
||||
agent=inv_ctx_t2_orch.agent,
|
||||
callback_context=cb_ctx_t2_orch,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# Orchestrator delegates to image_describer
|
||||
inv_ctx_t2_sub = self._make_invocation_context(
|
||||
@@ -4952,7 +4956,7 @@ class TestMultiSubagentToolLogging:
|
||||
agent=inv_ctx_t2_sub.agent,
|
||||
callback_context=cb_ctx_t2_sub,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# image_describer calls tool
|
||||
tool_2 = self._make_tool("describe_this_image")
|
||||
@@ -4964,28 +4968,28 @@ class TestMultiSubagentToolLogging:
|
||||
tool_args={"image_uri": "gs://b/img.jpg"},
|
||||
tool_context=tool_ctx_t2,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
await plugin.after_tool_callback(
|
||||
tool=tool_2,
|
||||
tool_args={"image_uri": "gs://b/img.jpg"},
|
||||
tool_context=tool_ctx_t2,
|
||||
result={"desc": "Scones on a table"},
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# image_describer done
|
||||
await plugin.after_agent_callback(
|
||||
agent=inv_ctx_t2_sub.agent,
|
||||
callback_context=cb_ctx_t2_sub,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
# Orchestrator done
|
||||
await plugin.after_agent_callback(
|
||||
agent=inv_ctx_t2_orch.agent,
|
||||
callback_context=cb_ctx_t2_orch,
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -5517,7 +5521,7 @@ class TestToolProvenance:
|
||||
tool_context=tool_ctx,
|
||||
error=RuntimeError("connection refused"),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await plugin.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -6695,7 +6699,7 @@ class TestTraceIdContinuity:
|
||||
await bq_plugin_inst.after_run_callback(
|
||||
invocation_context=invocation_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
# Collect all emitted rows.
|
||||
rows = await _get_captured_rows_async(
|
||||
@@ -6862,7 +6866,7 @@ class TestSpanIdConsistency:
|
||||
invocation_context=invocation_context
|
||||
)
|
||||
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -6928,7 +6932,7 @@ class TestSpanIdConsistency:
|
||||
invocation_context=invocation_context
|
||||
)
|
||||
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -6998,7 +7002,7 @@ class TestSpanIdConsistency:
|
||||
await bq_plugin_inst.after_run_callback(
|
||||
invocation_context=invocation_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -7315,7 +7319,7 @@ class TestStackLeakSafety:
|
||||
await bq_plugin_inst.after_run_callback(
|
||||
invocation_context=invocation_context
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
rows = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -7403,7 +7407,7 @@ class TestRootAgentNameAcrossInvocations:
|
||||
agent=inv1.agent, callback_context=cb1
|
||||
)
|
||||
await bq_plugin_inst.after_run_callback(invocation_context=inv1)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
rows_inv1 = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -7422,7 +7426,7 @@ class TestRootAgentNameAcrossInvocations:
|
||||
agent=inv2.agent, callback_context=cb2
|
||||
)
|
||||
await bq_plugin_inst.after_run_callback(invocation_context=inv2)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
|
||||
rows_inv2 = await _get_captured_rows_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
@@ -8707,7 +8711,7 @@ class TestAdkEnvelope:
|
||||
invocation_context=invocation_context,
|
||||
user_message=types.Content(role="user", parts=[types.Part(text="hi")]),
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -8745,7 +8749,7 @@ class TestAdkEnvelope:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -8790,7 +8794,7 @@ class TestAdkEnvelope:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
@@ -8820,7 +8824,7 @@ class TestC4AgentTransfer:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
rows = await _get_captured_rows_async(mock_write_client, dummy_arrow_schema)
|
||||
transfers = [r for r in rows if r["event_type"] == "AGENT_TRANSFER"]
|
||||
assert len(transfers) == 1
|
||||
@@ -8857,7 +8861,7 @@ class TestC5EventCompaction:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
rows = await _get_captured_rows_async(mock_write_client, dummy_arrow_schema)
|
||||
compactions = [r for r in rows if r["event_type"] == "EVENT_COMPACTION"]
|
||||
assert len(compactions) == 1
|
||||
@@ -8888,7 +8892,7 @@ class TestC6AgentStateCheckpoint:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
rows = await _get_captured_rows_async(mock_write_client, dummy_arrow_schema)
|
||||
cps = [r for r in rows if r["event_type"] == "AGENT_STATE_CHECKPOINT"]
|
||||
assert len(cps) == 1
|
||||
@@ -8913,7 +8917,7 @@ class TestC6AgentStateCheckpoint:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
rows = await _get_captured_rows_async(mock_write_client, dummy_arrow_schema)
|
||||
cps = [r for r in rows if r["event_type"] == "AGENT_STATE_CHECKPOINT"]
|
||||
assert len(cps) == 1
|
||||
@@ -8941,7 +8945,7 @@ class TestC6AgentStateCheckpoint:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
rows = await _get_captured_rows_async(mock_write_client, dummy_arrow_schema)
|
||||
cps = [r for r in rows if r["event_type"] == "AGENT_STATE_CHECKPOINT"]
|
||||
assert len(cps) == 1
|
||||
@@ -9098,7 +9102,7 @@ class TestC8ActionAttributes:
|
||||
await bq_plugin_inst.on_event_callback(
|
||||
invocation_context=invocation_context, event=event
|
||||
)
|
||||
await asyncio.sleep(0.01)
|
||||
await bq_plugin_inst.flush()
|
||||
log_entry = await _get_captured_event_dict_async(
|
||||
mock_write_client, dummy_arrow_schema
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user