Skip to content

Commit c3d5208

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

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

tests/test_polling.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,75 @@ def fetch_result() -> dict:
25512551
assert fetch_attempts["count"] == 1
25522552

25532553

2554+
def test_wait_for_job_result_does_not_retry_timeout_fetch_errors():
2555+
fetch_attempts = {"count": 0}
2556+
2557+
def fetch_result() -> dict:
2558+
fetch_attempts["count"] += 1
2559+
raise HyperbrowserTimeoutError("timed out internally")
2560+
2561+
with pytest.raises(HyperbrowserTimeoutError, match="timed out internally"):
2562+
wait_for_job_result(
2563+
operation_name="sync wait helper fetch timeout",
2564+
get_status=lambda: "completed",
2565+
is_terminal_status=lambda value: value == "completed",
2566+
fetch_result=fetch_result,
2567+
poll_interval_seconds=0.0001,
2568+
max_wait_seconds=1.0,
2569+
max_status_failures=5,
2570+
fetch_max_attempts=5,
2571+
fetch_retry_delay_seconds=0.0001,
2572+
)
2573+
2574+
assert fetch_attempts["count"] == 1
2575+
2576+
2577+
def test_wait_for_job_result_does_not_retry_stop_iteration_fetch_errors():
2578+
fetch_attempts = {"count": 0}
2579+
2580+
def fetch_result() -> dict:
2581+
fetch_attempts["count"] += 1
2582+
raise StopIteration("callback exhausted")
2583+
2584+
with pytest.raises(StopIteration, match="callback exhausted"):
2585+
wait_for_job_result(
2586+
operation_name="sync wait helper fetch stop-iteration",
2587+
get_status=lambda: "completed",
2588+
is_terminal_status=lambda value: value == "completed",
2589+
fetch_result=fetch_result,
2590+
poll_interval_seconds=0.0001,
2591+
max_wait_seconds=1.0,
2592+
max_status_failures=5,
2593+
fetch_max_attempts=5,
2594+
fetch_retry_delay_seconds=0.0001,
2595+
)
2596+
2597+
assert fetch_attempts["count"] == 1
2598+
2599+
2600+
def test_wait_for_job_result_does_not_retry_concurrent_cancelled_fetch_errors():
2601+
fetch_attempts = {"count": 0}
2602+
2603+
def fetch_result() -> dict:
2604+
fetch_attempts["count"] += 1
2605+
raise ConcurrentCancelledError()
2606+
2607+
with pytest.raises(ConcurrentCancelledError):
2608+
wait_for_job_result(
2609+
operation_name="sync wait helper fetch concurrent-cancelled",
2610+
get_status=lambda: "completed",
2611+
is_terminal_status=lambda value: value == "completed",
2612+
fetch_result=fetch_result,
2613+
poll_interval_seconds=0.0001,
2614+
max_wait_seconds=1.0,
2615+
max_status_failures=5,
2616+
fetch_max_attempts=5,
2617+
fetch_retry_delay_seconds=0.0001,
2618+
)
2619+
2620+
assert fetch_attempts["count"] == 1
2621+
2622+
25542623
def test_wait_for_job_result_retries_rate_limit_fetch_errors():
25552624
fetch_attempts = {"count": 0}
25562625

@@ -2778,6 +2847,84 @@ async def fetch_result() -> dict:
27782847
asyncio.run(run())
27792848

27802849

2850+
def test_wait_for_job_result_async_does_not_retry_timeout_fetch_errors():
2851+
async def run() -> None:
2852+
fetch_attempts = {"count": 0}
2853+
2854+
async def fetch_result() -> dict:
2855+
fetch_attempts["count"] += 1
2856+
raise HyperbrowserTimeoutError("timed out internally")
2857+
2858+
with pytest.raises(HyperbrowserTimeoutError, match="timed out internally"):
2859+
await wait_for_job_result_async(
2860+
operation_name="async wait helper fetch timeout",
2861+
get_status=lambda: asyncio.sleep(0, result="completed"),
2862+
is_terminal_status=lambda value: value == "completed",
2863+
fetch_result=fetch_result,
2864+
poll_interval_seconds=0.0001,
2865+
max_wait_seconds=1.0,
2866+
max_status_failures=5,
2867+
fetch_max_attempts=5,
2868+
fetch_retry_delay_seconds=0.0001,
2869+
)
2870+
2871+
assert fetch_attempts["count"] == 1
2872+
2873+
asyncio.run(run())
2874+
2875+
2876+
def test_wait_for_job_result_async_does_not_retry_stop_async_iteration_fetch_errors():
2877+
async def run() -> None:
2878+
fetch_attempts = {"count": 0}
2879+
2880+
async def fetch_result() -> dict:
2881+
fetch_attempts["count"] += 1
2882+
raise StopAsyncIteration("callback exhausted")
2883+
2884+
with pytest.raises(StopAsyncIteration, match="callback exhausted"):
2885+
await wait_for_job_result_async(
2886+
operation_name="async wait helper fetch stop-async-iteration",
2887+
get_status=lambda: asyncio.sleep(0, result="completed"),
2888+
is_terminal_status=lambda value: value == "completed",
2889+
fetch_result=fetch_result,
2890+
poll_interval_seconds=0.0001,
2891+
max_wait_seconds=1.0,
2892+
max_status_failures=5,
2893+
fetch_max_attempts=5,
2894+
fetch_retry_delay_seconds=0.0001,
2895+
)
2896+
2897+
assert fetch_attempts["count"] == 1
2898+
2899+
asyncio.run(run())
2900+
2901+
2902+
def test_wait_for_job_result_async_does_not_retry_concurrent_cancelled_fetch_errors():
2903+
async def run() -> None:
2904+
fetch_attempts = {"count": 0}
2905+
2906+
async def fetch_result() -> dict:
2907+
fetch_attempts["count"] += 1
2908+
raise ConcurrentCancelledError()
2909+
2910+
with pytest.raises(ConcurrentCancelledError):
2911+
await wait_for_job_result_async(
2912+
operation_name="async wait helper fetch concurrent-cancelled",
2913+
get_status=lambda: asyncio.sleep(0, result="completed"),
2914+
is_terminal_status=lambda value: value == "completed",
2915+
fetch_result=fetch_result,
2916+
poll_interval_seconds=0.0001,
2917+
max_wait_seconds=1.0,
2918+
max_status_failures=5,
2919+
fetch_max_attempts=5,
2920+
fetch_retry_delay_seconds=0.0001,
2921+
)
2922+
2923+
assert fetch_attempts["count"] == 1
2924+
2925+
asyncio.run(run())
2926+
2927+
27812928
def test_wait_for_job_result_async_retries_rate_limit_fetch_errors():
27822929
async def run() -> None:
27832930
fetch_attempts = {"count": 0}

0 commit comments

Comments
 (0)