mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-25 12:13:58 +00:00
test: add regression test for DuckDuckGo asyncio.wait_for timeout guard
Made-with: Cursor
This commit is contained in:
parent
6bd2950b99
commit
4b4d8b506d
@ -1,5 +1,7 @@
|
|||||||
"""Tests for multi-provider web search."""
|
"""Tests for multi-provider web search."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -205,3 +207,25 @@ async def test_jina_search_uses_path_encoded_query(monkeypatch):
|
|||||||
assert calls["params"] in (None, {})
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user