File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -298,7 +298,24 @@ async def retry_operation_async(
298298 failures = 0
299299 while True :
300300 try :
301- return await operation ()
301+ operation_result = operation ()
302+ except Exception as exc :
303+ failures += 1
304+ if failures >= max_attempts :
305+ raise HyperbrowserError (
306+ f"{ operation_name } failed after { max_attempts } attempts: { exc } "
307+ ) from exc
308+ await asyncio .sleep (retry_delay_seconds )
309+ continue
310+
311+ operation_awaitable = _ensure_awaitable (
312+ operation_result ,
313+ callback_name = "operation" ,
314+ operation_name = operation_name ,
315+ )
316+
317+ try :
318+ return await operation_awaitable
302319 except Exception as exc :
303320 failures += 1
304321 if failures >= max_attempts :
Original file line number Diff line number Diff line change @@ -177,6 +177,21 @@ async def operation() -> str:
177177 asyncio .run (run ())
178178
179179
180+ def test_retry_operation_async_rejects_non_awaitable_operation_result () -> None :
181+ async def run () -> None :
182+ with pytest .raises (
183+ HyperbrowserError , match = "operation must return an awaitable"
184+ ):
185+ await retry_operation_async (
186+ operation_name = "invalid-async-retry-awaitable" ,
187+ operation = lambda : "ok" , # type: ignore[return-value]
188+ max_attempts = 2 ,
189+ retry_delay_seconds = 0.0001 ,
190+ )
191+
192+ asyncio .run (run ())
193+
194+
180195def test_async_poll_until_terminal_status_allows_immediate_terminal_on_zero_max_wait ():
181196 async def run () -> None :
182197 status = await poll_until_terminal_status_async (
You can’t perform that action at this time.
0 commit comments