Skip to content

Commit dad7cd8

Browse files
Expand wait-helper cancellation and loop-runtime coverage
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent c3d5208 commit dad7cd8

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

tests/test_polling.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,6 +2497,35 @@ def fetch_result() -> dict:
24972497
assert fetch_attempts["count"] == 0
24982498

24992499

2500+
def test_wait_for_job_result_does_not_retry_concurrent_cancelled_status_errors():
2501+
status_attempts = {"count": 0}
2502+
fetch_attempts = {"count": 0}
2503+
2504+
def get_status() -> str:
2505+
status_attempts["count"] += 1
2506+
raise ConcurrentCancelledError()
2507+
2508+
def fetch_result() -> dict:
2509+
fetch_attempts["count"] += 1
2510+
return {"ok": True}
2511+
2512+
with pytest.raises(ConcurrentCancelledError):
2513+
wait_for_job_result(
2514+
operation_name="sync wait helper status concurrent-cancelled",
2515+
get_status=get_status,
2516+
is_terminal_status=lambda value: value == "completed",
2517+
fetch_result=fetch_result,
2518+
poll_interval_seconds=0.0001,
2519+
max_wait_seconds=1.0,
2520+
max_status_failures=5,
2521+
fetch_max_attempts=5,
2522+
fetch_retry_delay_seconds=0.0001,
2523+
)
2524+
2525+
assert status_attempts["count"] == 1
2526+
assert fetch_attempts["count"] == 0
2527+
2528+
25002529
def test_wait_for_job_result_retries_rate_limit_status_errors():
25012530
status_attempts = {"count": 0}
25022531
fetch_attempts = {"count": 0}
@@ -2620,6 +2649,29 @@ def fetch_result() -> dict:
26202649
assert fetch_attempts["count"] == 1
26212650

26222651

2652+
def test_wait_for_job_result_does_not_retry_loop_runtime_fetch_errors():
2653+
fetch_attempts = {"count": 0}
2654+
2655+
def fetch_result() -> dict:
2656+
fetch_attempts["count"] += 1
2657+
raise RuntimeError("Task is bound to a different event loop")
2658+
2659+
with pytest.raises(RuntimeError, match="different event loop"):
2660+
wait_for_job_result(
2661+
operation_name="sync wait helper fetch loop-runtime",
2662+
get_status=lambda: "completed",
2663+
is_terminal_status=lambda value: value == "completed",
2664+
fetch_result=fetch_result,
2665+
poll_interval_seconds=0.0001,
2666+
max_wait_seconds=1.0,
2667+
max_status_failures=5,
2668+
fetch_max_attempts=5,
2669+
fetch_retry_delay_seconds=0.0001,
2670+
)
2671+
2672+
assert fetch_attempts["count"] == 1
2673+
2674+
26232675
def test_wait_for_job_result_retries_rate_limit_fetch_errors():
26242676
fetch_attempts = {"count": 0}
26252677

@@ -2787,6 +2839,38 @@ async def fetch_result() -> dict:
27872839
asyncio.run(run())
27882840

27892841

2842+
def test_wait_for_job_result_async_does_not_retry_concurrent_cancelled_status_errors():
2843+
async def run() -> None:
2844+
status_attempts = {"count": 0}
2845+
fetch_attempts = {"count": 0}
2846+
2847+
async def get_status() -> str:
2848+
status_attempts["count"] += 1
2849+
raise ConcurrentCancelledError()
2850+
2851+
async def fetch_result() -> dict:
2852+
fetch_attempts["count"] += 1
2853+
return {"ok": True}
2854+
2855+
with pytest.raises(ConcurrentCancelledError):
2856+
await wait_for_job_result_async(
2857+
operation_name="async wait helper status concurrent-cancelled",
2858+
get_status=get_status,
2859+
is_terminal_status=lambda value: value == "completed",
2860+
fetch_result=fetch_result,
2861+
poll_interval_seconds=0.0001,
2862+
max_wait_seconds=1.0,
2863+
max_status_failures=5,
2864+
fetch_max_attempts=5,
2865+
fetch_retry_delay_seconds=0.0001,
2866+
)
2867+
2868+
assert status_attempts["count"] == 1
2869+
assert fetch_attempts["count"] == 0
2870+
2871+
asyncio.run(run())
2872+
2873+
27902874
def test_wait_for_job_result_async_retries_rate_limit_status_errors():
27912875
async def run() -> None:
27922876
status_attempts = {"count": 0}
@@ -2925,6 +3009,32 @@ async def fetch_result() -> dict:
29253009
asyncio.run(run())
29263010

29273011

3012+
def test_wait_for_job_result_async_does_not_retry_loop_runtime_fetch_errors():
3013+
async def run() -> None:
3014+
fetch_attempts = {"count": 0}
3015+
3016+
async def fetch_result() -> dict:
3017+
fetch_attempts["count"] += 1
3018+
raise RuntimeError("Event loop is closed")
3019+
3020+
with pytest.raises(RuntimeError, match="Event loop is closed"):
3021+
await wait_for_job_result_async(
3022+
operation_name="async wait helper fetch loop-runtime",
3023+
get_status=lambda: asyncio.sleep(0, result="completed"),
3024+
is_terminal_status=lambda value: value == "completed",
3025+
fetch_result=fetch_result,
3026+
poll_interval_seconds=0.0001,
3027+
max_wait_seconds=1.0,
3028+
max_status_failures=5,
3029+
fetch_max_attempts=5,
3030+
fetch_retry_delay_seconds=0.0001,
3031+
)
3032+
3033+
assert fetch_attempts["count"] == 1
3034+
3035+
asyncio.run(run())
3036+
3037+
29283038
def test_wait_for_job_result_async_retries_rate_limit_fetch_errors():
29293039
async def run() -> None:
29303040
fetch_attempts = {"count": 0}

0 commit comments

Comments
 (0)