Skip to content

Commit a1432fa

Browse files
committed
Make retry delays zero in the custom tests instead of patching anyio.sleep
anyio before 4.12 implements lowlevel.checkpoint as sleep(0), so the global patch made the async event-feed poll spin forever under --resolution lowest-direct. Signed-off-by: Shrijayan <81805145+shrijayan@users.noreply.github.com>
1 parent 6f9eb48 commit a1432fa

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎tests/custom/conftest.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
from opencode import Opencode, AsyncOpencode
9+
from opencode._base_client import BaseClient
910

1011
BASE_URL = "http://opencode.test"
1112
PASSWORD = "test-password"
@@ -36,11 +37,9 @@ async def async_client(mock_api: respx.MockRouter) -> AsyncIterator[AsyncOpencod
3637

3738
@pytest.fixture(autouse=True)
3839
def _no_retry_sleep(monkeypatch: pytest.MonkeyPatch) -> None:
39-
"""Retries back off with real sleeps; skip them so tests stay fast."""
40+
"""Retries back off with real sleeps; make the delay zero so tests stay fast.
4041
41-
async def instant(_: float) -> None:
42-
return None
43-
44-
monkeypatch.setattr("opencode._base_client.time.sleep", lambda _: None)
45-
monkeypatch.setattr("opencode._base_client.anyio.sleep", instant)
46-
monkeypatch.setattr("opencode._base_client.asyncio.sleep", instant)
42+
Patching ``anyio.sleep`` itself would also patch ``anyio.lowlevel.checkpoint`` on anyio
43+
releases that implement it as ``sleep(0)``, and a task polling with it would never yield.
44+
"""
45+
monkeypatch.setattr(BaseClient, "_calculate_retry_timeout", lambda *_args, **_kwargs: 0.0)

‎tests/custom/test_events.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def wait_open(self, count: int) -> SyncFeed:
103103

104104

105105
class AsyncFeed:
106-
"""The async counterpart of ``SyncFeed``. It polls, since ``anyio.sleep`` is patched in tests."""
106+
"""The async counterpart of ``SyncFeed``. It polls with ``anyio.lowlevel.checkpoint``."""
107107

108108
def __init__(self) -> None:
109109
self.chunks: collections.deque[bytes] = collections.deque()
@@ -304,7 +304,7 @@ def anyio_backend(request: pytest.FixtureRequest) -> str:
304304
async def _wait_feed(server: Server, count: int) -> AsyncFeed:
305305
with anyio.fail_after(5):
306306
while len(server.feeds) < count:
307-
await anyio.lowlevel.checkpoint() # anyio.sleep is patched to return at once
307+
await anyio.lowlevel.checkpoint()
308308
feed = server.feeds[count - 1]
309309
assert isinstance(feed, AsyncFeed)
310310
return feed

0 commit comments

Comments
 (0)