Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 5e01443

Browse files
committed
fix unit tests
1 parent abf4a29 commit 5e01443

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

google/cloud/storage/_experimental/asyncio/retry/bidi_stream_retry_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ async def attempt():
5858

5959
wrapped_attempt = retry_policy(attempt)
6060

61-
await wrapped_attempt()
61+
await wrapped_attempt()

tests/unit/asyncio/retry/test_bidi_stream_retry_manager.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,28 @@ async def mock_stream_opener(*args, **kwargs):
143143
yield
144144
raise exceptions.ServiceUnavailable("Service is always down")
145145

146-
fast_retry = AsyncRetry(predicate=_is_retriable, deadline=0.1, initial=0.2)
146+
fast_retry = AsyncRetry(
147+
predicate=_is_retriable, deadline=1, initial=0.6, multiplier=1.5
148+
)
147149
retry_manager = manager._BidiStreamRetryManager(
148150
strategy=mock_strategy, stream_opener=mock_stream_opener
149151
)
150-
with pytest.raises(exceptions.RetryError, match="Timeout of 0.1s exceeded"):
151-
await retry_manager.execute(initial_state={}, retry_policy=fast_retry)
152152

153-
mock_strategy.recover_state_on_failure.assert_called_once()
153+
now = 0
154+
155+
def monotonic_mock():
156+
return now
157+
158+
async def sleep_mock(delay):
159+
nonlocal now
160+
now += delay
161+
162+
with mock.patch("time.monotonic", new=monotonic_mock):
163+
with mock.patch("asyncio.sleep", new=sleep_mock):
164+
with pytest.raises(exceptions.RetryError):
165+
await retry_manager.execute(initial_state={}, retry_policy=fast_retry)
166+
167+
assert mock_strategy.recover_state_on_failure.call_count == 2
154168

155169
@pytest.mark.asyncio
156170
async def test_execute_fails_immediately_on_non_retriable_error(self):

0 commit comments

Comments
 (0)