Skip to content

Commit e11e3a1

Browse files
Add coverage for shared wait_for_job_result helpers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent b750256 commit e11e3a1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/test_polling.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
poll_until_terminal_status_async,
1010
retry_operation,
1111
retry_operation_async,
12+
wait_for_job_result,
13+
wait_for_job_result_async,
1214
)
1315
from hyperbrowser.exceptions import (
1416
HyperbrowserError,
@@ -255,3 +257,42 @@ async def run() -> None:
255257
)
256258

257259
asyncio.run(run())
260+
261+
262+
def test_wait_for_job_result_returns_fetched_value():
263+
status_values = iter(["running", "completed"])
264+
265+
result = wait_for_job_result(
266+
operation_name="sync wait helper",
267+
get_status=lambda: next(status_values),
268+
is_terminal_status=lambda value: value == "completed",
269+
fetch_result=lambda: {"ok": True},
270+
poll_interval_seconds=0.0001,
271+
max_wait_seconds=1.0,
272+
max_status_failures=2,
273+
fetch_max_attempts=2,
274+
fetch_retry_delay_seconds=0.0001,
275+
)
276+
277+
assert result == {"ok": True}
278+
279+
280+
def test_wait_for_job_result_async_returns_fetched_value():
281+
async def run() -> None:
282+
status_values = iter(["running", "completed"])
283+
284+
result = await wait_for_job_result_async(
285+
operation_name="async wait helper",
286+
get_status=lambda: asyncio.sleep(0, result=next(status_values)),
287+
is_terminal_status=lambda value: value == "completed",
288+
fetch_result=lambda: asyncio.sleep(0, result={"ok": True}),
289+
poll_interval_seconds=0.0001,
290+
max_wait_seconds=1.0,
291+
max_status_failures=2,
292+
fetch_max_attempts=2,
293+
fetch_retry_delay_seconds=0.0001,
294+
)
295+
296+
assert result == {"ok": True}
297+
298+
asyncio.run(run())

0 commit comments

Comments
 (0)