test: add regression test for DuckDuckGo asyncio.wait_for timeout guard

Made-with: Cursor
This commit is contained in:
Xubin Ren 2026-04-05 18:18:59 +00:00 committed by Xubin Ren
parent 6bd2950b99
commit 4b4d8b506d

View File

@ -1,5 +1,7 @@
"""Tests for multi-provider web search."""
import asyncio
import httpx
import pytest
@ -205,3 +207,25 @@ async def test_jina_search_uses_path_encoded_query(monkeypatch):
assert calls["params"] in (None, {})
@pytest.mark.asyncio
async def test_duckduckgo_timeout_returns_error(monkeypatch):
"""asyncio.wait_for guard should fire when DDG search hangs."""
import threading
gate = threading.Event()
class HangingDDGS:
def __init__(self, **kw):
pass
def text(self, query, max_results=5):
gate.wait(timeout=10)
return []
monkeypatch.setattr("ddgs.DDGS", HangingDDGS)
tool = _tool(provider="duckduckgo")
tool.config.timeout = 0.2
result = await tool.execute(query="test")
gate.set()
assert "Error" in result