Skip to content

Commit d19bc40

Browse files
Expand wait-helper status non-retryable coverage
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent c2bb348 commit d19bc40

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

‎tests/test_polling.py‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,64 @@ def fetch_result() -> dict:
24392439
assert fetch_attempts["count"] == 0
24402440

24412441

2442+
def test_wait_for_job_result_does_not_retry_timeout_status_errors():
2443+
status_attempts = {"count": 0}
2444+
fetch_attempts = {"count": 0}
2445+
2446+
def get_status() -> str:
2447+
status_attempts["count"] += 1
2448+
raise HyperbrowserTimeoutError("timed out internally")
2449+
2450+
def fetch_result() -> dict:
2451+
fetch_attempts["count"] += 1
2452+
return {"ok": True}
2453+
2454+
with pytest.raises(HyperbrowserTimeoutError, match="timed out internally"):
2455+
wait_for_job_result(
2456+
operation_name="sync wait helper status timeout",
2457+
get_status=get_status,
2458+
is_terminal_status=lambda value: value == "completed",
2459+
fetch_result=fetch_result,
2460+
poll_interval_seconds=0.0001,
2461+
max_wait_seconds=1.0,
2462+
max_status_failures=5,
2463+
fetch_max_attempts=5,
2464+
fetch_retry_delay_seconds=0.0001,
2465+
)
2466+
2467+
assert status_attempts["count"] == 1
2468+
assert fetch_attempts["count"] == 0
2469+
2470+
2471+
def test_wait_for_job_result_does_not_retry_stop_iteration_status_errors():
2472+
status_attempts = {"count": 0}
2473+
fetch_attempts = {"count": 0}
2474+
2475+
def get_status() -> str:
2476+
status_attempts["count"] += 1
2477+
raise StopIteration("callback exhausted")
2478+
2479+
def fetch_result() -> dict:
2480+
fetch_attempts["count"] += 1
2481+
return {"ok": True}
2482+
2483+
with pytest.raises(StopIteration, match="callback exhausted"):
2484+
wait_for_job_result(
2485+
operation_name="sync wait helper status stop-iteration",
2486+
get_status=get_status,
2487+
is_terminal_status=lambda value: value == "completed",
2488+
fetch_result=fetch_result,
2489+
poll_interval_seconds=0.0001,
2490+
max_wait_seconds=1.0,
2491+
max_status_failures=5,
2492+
fetch_max_attempts=5,
2493+
fetch_retry_delay_seconds=0.0001,
2494+
)
2495+
2496+
assert status_attempts["count"] == 1
2497+
assert fetch_attempts["count"] == 0
2498+
2499+
24422500
def test_wait_for_job_result_retries_rate_limit_status_errors():
24432501
status_attempts = {"count": 0}
24442502
fetch_attempts = {"count": 0}
@@ -2596,6 +2654,70 @@ async def fetch_result() -> dict:
25962654
asyncio.run(run())
25972655

25982656

2657+
def test_wait_for_job_result_async_does_not_retry_timeout_status_errors():
2658+
async def run() -> None:
2659+
status_attempts = {"count": 0}
2660+
fetch_attempts = {"count": 0}
2661+
2662+
async def get_status() -> str:
2663+
status_attempts["count"] += 1
2664+
raise HyperbrowserTimeoutError("timed out internally")
2665+
2666+
async def fetch_result() -> dict:
2667+
fetch_attempts["count"] += 1
2668+
return {"ok": True}
2669+
2670+
with pytest.raises(HyperbrowserTimeoutError, match="timed out internally"):
2671+
await wait_for_job_result_async(
2672+
operation_name="async wait helper status timeout",
2673+
get_status=get_status,
2674+
is_terminal_status=lambda value: value == "completed",
2675+
fetch_result=fetch_result,
2676+
poll_interval_seconds=0.0001,
2677+
max_wait_seconds=1.0,
2678+
max_status_failures=5,
2679+
fetch_max_attempts=5,
2680+
fetch_retry_delay_seconds=0.0001,
2681+
)
2682+
2683+
assert status_attempts["count"] == 1
2684+
assert fetch_attempts["count"] == 0
2685+
2686+
asyncio.run(run())
2687+
2688+
2689+
def test_wait_for_job_result_async_does_not_retry_stop_async_iteration_status_errors():
2690+
async def run() -> None:
2691+
status_attempts = {"count": 0}
2692+
fetch_attempts = {"count": 0}
2693+
2694+
async def get_status() -> str:
2695+
status_attempts["count"] += 1
2696+
raise StopAsyncIteration("callback exhausted")
2697+
2698+
async def fetch_result() -> dict:
2699+
fetch_attempts["count"] += 1
2700+
return {"ok": True}
2701+
2702+
with pytest.raises(StopAsyncIteration, match="callback exhausted"):
2703+
await wait_for_job_result_async(
2704+
operation_name="async wait helper status stop-async-iteration",
2705+
get_status=get_status,
2706+
is_terminal_status=lambda value: value == "completed",
2707+
fetch_result=fetch_result,
2708+
poll_interval_seconds=0.0001,
2709+
max_wait_seconds=1.0,
2710+
max_status_failures=5,
2711+
fetch_max_attempts=5,
2712+
fetch_retry_delay_seconds=0.0001,
2713+
)
2714+
2715+
assert status_attempts["count"] == 1
2716+
assert fetch_attempts["count"] == 0
2717+
2718+
asyncio.run(run())
2719+
2720+
25992721
def test_wait_for_job_result_async_retries_rate_limit_status_errors():
26002722
async def run() -> None:
26012723
status_attempts = {"count": 0}

0 commit comments

Comments
 (0)