Skip to content

Commit c263e64

Browse files
Validate non-negative max_wait_seconds in polling helpers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 1383530 commit c263e64

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

hyperbrowser/client/polling.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def _validate_poll_interval(poll_interval_seconds: float) -> None:
3030
raise HyperbrowserError("poll_interval_seconds must be non-negative")
3131

3232

33+
def _validate_max_wait_seconds(max_wait_seconds: Optional[float]) -> None:
34+
if max_wait_seconds is not None and max_wait_seconds < 0:
35+
raise HyperbrowserError("max_wait_seconds must be non-negative")
36+
37+
3338
def has_exceeded_max_wait(start_time: float, max_wait_seconds: Optional[float]) -> bool:
3439
return (
3540
max_wait_seconds is not None
@@ -47,6 +52,7 @@ def poll_until_terminal_status(
4752
max_status_failures: int = 5,
4853
) -> str:
4954
_validate_poll_interval(poll_interval_seconds)
55+
_validate_max_wait_seconds(max_wait_seconds)
5056
_validate_retry_config(
5157
max_attempts=1,
5258
retry_delay_seconds=0,
@@ -112,6 +118,7 @@ async def poll_until_terminal_status_async(
112118
max_status_failures: int = 5,
113119
) -> str:
114120
_validate_poll_interval(poll_interval_seconds)
121+
_validate_max_wait_seconds(max_wait_seconds)
115122
_validate_retry_config(
116123
max_attempts=1,
117124
retry_delay_seconds=0,
@@ -178,6 +185,7 @@ def collect_paginated_results(
178185
max_attempts: int,
179186
retry_delay_seconds: float,
180187
) -> None:
188+
_validate_max_wait_seconds(max_wait_seconds)
181189
_validate_retry_config(
182190
max_attempts=max_attempts,
183191
retry_delay_seconds=retry_delay_seconds,
@@ -220,6 +228,7 @@ async def collect_paginated_results_async(
220228
max_attempts: int,
221229
retry_delay_seconds: float,
222230
) -> None:
231+
_validate_max_wait_seconds(max_wait_seconds)
223232
_validate_retry_config(
224233
max_attempts=max_attempts,
225234
retry_delay_seconds=retry_delay_seconds,
@@ -269,6 +278,7 @@ def wait_for_job_result(
269278
max_status_failures=max_status_failures,
270279
)
271280
_validate_poll_interval(poll_interval_seconds)
281+
_validate_max_wait_seconds(max_wait_seconds)
272282
poll_until_terminal_status(
273283
operation_name=operation_name,
274284
get_status=get_status,
@@ -303,6 +313,7 @@ async def wait_for_job_result_async(
303313
max_status_failures=max_status_failures,
304314
)
305315
_validate_poll_interval(poll_interval_seconds)
316+
_validate_max_wait_seconds(max_wait_seconds)
306317
await poll_until_terminal_status_async(
307318
operation_name=operation_name,
308319
get_status=get_status,

tests/test_polling.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,17 @@ def test_polling_helpers_validate_retry_and_interval_configuration():
376376
poll_interval_seconds=-0.1,
377377
max_wait_seconds=1.0,
378378
)
379+
380+
with pytest.raises(
381+
HyperbrowserError, match="max_wait_seconds must be non-negative"
382+
):
383+
collect_paginated_results(
384+
operation_name="invalid-max-wait",
385+
get_next_page=lambda page: {"current": 1, "total": 1, "items": []},
386+
get_current_page_batch=lambda response: response["current"],
387+
get_total_page_batches=lambda response: response["total"],
388+
on_page_success=lambda response: None,
389+
max_wait_seconds=-1.0,
390+
max_attempts=1,
391+
retry_delay_seconds=0.0,
392+
)

0 commit comments

Comments
 (0)