Skip to content

Commit 1936d46

Browse files
committed
fix(workflow): Disable sleep in message sample during pytest
Change-Id: I561cd00fcbc132bb3198f6ffb02b7938f5eeda25
1 parent 569f6b9 commit 1936d46

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • contributing/workflow_samples/message

contributing/workflow_samples/message/agent.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414

1515
import asyncio
1616
import base64
17+
import os
1718
from typing import Any
1819

1920
from google.adk import Event
2021
from google.adk import Workflow
2122
from google.genai import types
2223

2324

25+
async def sleep_if_not_pytest(seconds: float):
26+
if "PYTEST_CURRENT_TEST" not in os.environ:
27+
await asyncio.sleep(seconds)
28+
29+
2430
def send_string(node_input: Any = None):
2531
"""Sends a single string message."""
2632
yield Event(message="#1 This is a simple string message.")
@@ -48,13 +54,13 @@ def send_multimodal(node_input: Any = None):
4854
async def multiple_messages(node_input: Any = None):
4955
"""Sends multiple complete messages from the same node with an interval."""
5056
yield Event(message="#3 Multiple messages")
51-
await asyncio.sleep(1.0)
57+
await sleep_if_not_pytest(1.0)
5258

5359
yield Event(message="Processing step 1...")
54-
await asyncio.sleep(1.0)
60+
await sleep_if_not_pytest(1.0)
5561

5662
yield Event(message="Processing step 2...")
57-
await asyncio.sleep(1.0)
63+
await sleep_if_not_pytest(1.0)
5864

5965
yield Event(message="Done processing.")
6066

@@ -79,7 +85,7 @@ async def stream_sentence(node_input: Any = None):
7985
for i in range(0, len(sentence), 5):
8086
chunk = sentence[i : i + 5]
8187
yield Event(message=chunk, partial=True)
82-
await asyncio.sleep(0.2)
88+
await sleep_if_not_pytest(0.2)
8389

8490

8591
root_agent = Workflow(

0 commit comments

Comments
 (0)