Skip to content

Commit 3bab038

Browse files
Expand polling tests for paginated failure and timeout paths
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 9c990bc commit 3bab038

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/test_polling.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,37 @@ async def run() -> None:
221221
assert collected == ["a", "b"]
222222

223223
asyncio.run(run())
224+
225+
226+
def test_collect_paginated_results_raises_after_page_failures():
227+
with pytest.raises(HyperbrowserError, match="Failed to fetch page batch 1"):
228+
collect_paginated_results(
229+
operation_name="sync paginated failure",
230+
get_next_page=lambda page: (_ for _ in ()).throw(ValueError("boom")),
231+
get_current_page_batch=lambda response: response["current"],
232+
get_total_page_batches=lambda response: response["total"],
233+
on_page_success=lambda response: None,
234+
max_wait_seconds=1.0,
235+
max_attempts=2,
236+
retry_delay_seconds=0.0001,
237+
)
238+
239+
240+
def test_collect_paginated_results_async_times_out():
241+
async def run() -> None:
242+
with pytest.raises(
243+
HyperbrowserTimeoutError,
244+
match="Timed out fetching paginated results for async paginated timeout",
245+
):
246+
await collect_paginated_results_async(
247+
operation_name="async paginated timeout",
248+
get_next_page=lambda page: asyncio.sleep(0, result={"current": 0, "total": 1, "items": []}),
249+
get_current_page_batch=lambda response: response["current"],
250+
get_total_page_batches=lambda response: response["total"],
251+
on_page_success=lambda response: None,
252+
max_wait_seconds=0.001,
253+
max_attempts=2,
254+
retry_delay_seconds=0.01,
255+
)
256+
257+
asyncio.run(run())

0 commit comments

Comments
 (0)