|
9 | 9 | poll_until_terminal_status_async, |
10 | 10 | retry_operation, |
11 | 11 | retry_operation_async, |
| 12 | + wait_for_job_result, |
| 13 | + wait_for_job_result_async, |
12 | 14 | ) |
13 | 15 | from hyperbrowser.exceptions import ( |
14 | 16 | HyperbrowserError, |
@@ -255,3 +257,42 @@ async def run() -> None: |
255 | 257 | ) |
256 | 258 |
|
257 | 259 | asyncio.run(run()) |
| 260 | + |
| 261 | + |
| 262 | +def test_wait_for_job_result_returns_fetched_value(): |
| 263 | + status_values = iter(["running", "completed"]) |
| 264 | + |
| 265 | + result = wait_for_job_result( |
| 266 | + operation_name="sync wait helper", |
| 267 | + get_status=lambda: next(status_values), |
| 268 | + is_terminal_status=lambda value: value == "completed", |
| 269 | + fetch_result=lambda: {"ok": True}, |
| 270 | + poll_interval_seconds=0.0001, |
| 271 | + max_wait_seconds=1.0, |
| 272 | + max_status_failures=2, |
| 273 | + fetch_max_attempts=2, |
| 274 | + fetch_retry_delay_seconds=0.0001, |
| 275 | + ) |
| 276 | + |
| 277 | + assert result == {"ok": True} |
| 278 | + |
| 279 | + |
| 280 | +def test_wait_for_job_result_async_returns_fetched_value(): |
| 281 | + async def run() -> None: |
| 282 | + status_values = iter(["running", "completed"]) |
| 283 | + |
| 284 | + result = await wait_for_job_result_async( |
| 285 | + operation_name="async wait helper", |
| 286 | + get_status=lambda: asyncio.sleep(0, result=next(status_values)), |
| 287 | + is_terminal_status=lambda value: value == "completed", |
| 288 | + fetch_result=lambda: asyncio.sleep(0, result={"ok": True}), |
| 289 | + poll_interval_seconds=0.0001, |
| 290 | + max_wait_seconds=1.0, |
| 291 | + max_status_failures=2, |
| 292 | + fetch_max_attempts=2, |
| 293 | + fetch_retry_delay_seconds=0.0001, |
| 294 | + ) |
| 295 | + |
| 296 | + assert result == {"ok": True} |
| 297 | + |
| 298 | + asyncio.run(run()) |
0 commit comments