Skip to content

Commit 3c96fce

Browse files
Expand wait-helper bytes-like status path fallback coverage
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent c4744a2 commit 3c96fce

1 file changed

Lines changed: 138 additions & 0 deletions

File tree

tests/test_polling.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,6 +3877,38 @@ def fetch_result() -> dict:
38773877
assert fetch_attempts["count"] == 0
38783878

38793879

3880+
def test_wait_for_job_result_does_not_retry_bytes_like_status_errors():
3881+
status_attempts = {"count": 0}
3882+
fetch_attempts = {"count": 0}
3883+
3884+
def get_status() -> str:
3885+
status_attempts["count"] += 1
3886+
raise HyperbrowserError(
3887+
"client failure",
3888+
status_code=array("B", [52, 48, 48]), # type: ignore[arg-type]
3889+
)
3890+
3891+
def fetch_result() -> dict:
3892+
fetch_attempts["count"] += 1
3893+
return {"ok": True}
3894+
3895+
with pytest.raises(HyperbrowserError, match="client failure"):
3896+
wait_for_job_result(
3897+
operation_name="sync wait helper status bytes-like client error",
3898+
get_status=get_status,
3899+
is_terminal_status=lambda value: value == "completed",
3900+
fetch_result=fetch_result,
3901+
poll_interval_seconds=0.0001,
3902+
max_wait_seconds=1.0,
3903+
max_status_failures=5,
3904+
fetch_max_attempts=5,
3905+
fetch_retry_delay_seconds=0.0001,
3906+
)
3907+
3908+
assert status_attempts["count"] == 1
3909+
assert fetch_attempts["count"] == 0
3910+
3911+
38803912
def test_wait_for_job_result_retries_overlong_numeric_bytes_status_errors():
38813913
status_attempts = {"count": 0}
38823914
fetch_attempts = {"count": 0}
@@ -3911,6 +3943,40 @@ def fetch_result() -> dict:
39113943
assert fetch_attempts["count"] == 1
39123944

39133945

3946+
def test_wait_for_job_result_retries_overlong_bytes_like_status_errors():
3947+
status_attempts = {"count": 0}
3948+
fetch_attempts = {"count": 0}
3949+
3950+
def get_status() -> str:
3951+
status_attempts["count"] += 1
3952+
if status_attempts["count"] < 3:
3953+
raise HyperbrowserError(
3954+
"oversized status metadata",
3955+
status_code=array("B", [52, 48, 48, 48, 48, 48, 48]), # type: ignore[arg-type]
3956+
)
3957+
return "completed"
3958+
3959+
def fetch_result() -> dict:
3960+
fetch_attempts["count"] += 1
3961+
return {"ok": True}
3962+
3963+
result = wait_for_job_result(
3964+
operation_name="sync wait helper status oversized bytes-like retries",
3965+
get_status=get_status,
3966+
is_terminal_status=lambda value: value == "completed",
3967+
fetch_result=fetch_result,
3968+
poll_interval_seconds=0.0001,
3969+
max_wait_seconds=1.0,
3970+
max_status_failures=5,
3971+
fetch_max_attempts=5,
3972+
fetch_retry_delay_seconds=0.0001,
3973+
)
3974+
3975+
assert result == {"ok": True}
3976+
assert status_attempts["count"] == 3
3977+
assert fetch_attempts["count"] == 1
3978+
3979+
39143980
def test_wait_for_job_result_does_not_retry_broken_executor_status_errors():
39153981
status_attempts = {"count": 0}
39163982
fetch_attempts = {"count": 0}
@@ -4752,6 +4818,41 @@ async def fetch_result() -> dict:
47524818
asyncio.run(run())
47534819

47544820

4821+
def test_wait_for_job_result_async_does_not_retry_bytes_like_status_errors():
4822+
async def run() -> None:
4823+
status_attempts = {"count": 0}
4824+
fetch_attempts = {"count": 0}
4825+
4826+
async def get_status() -> str:
4827+
status_attempts["count"] += 1
4828+
raise HyperbrowserError(
4829+
"client failure",
4830+
status_code=array("B", [52, 48, 52]), # type: ignore[arg-type]
4831+
)
4832+
4833+
async def fetch_result() -> dict:
4834+
fetch_attempts["count"] += 1
4835+
return {"ok": True}
4836+
4837+
with pytest.raises(HyperbrowserError, match="client failure"):
4838+
await wait_for_job_result_async(
4839+
operation_name="async wait helper status bytes-like client error",
4840+
get_status=get_status,
4841+
is_terminal_status=lambda value: value == "completed",
4842+
fetch_result=fetch_result,
4843+
poll_interval_seconds=0.0001,
4844+
max_wait_seconds=1.0,
4845+
max_status_failures=5,
4846+
fetch_max_attempts=5,
4847+
fetch_retry_delay_seconds=0.0001,
4848+
)
4849+
4850+
assert status_attempts["count"] == 1
4851+
assert fetch_attempts["count"] == 0
4852+
4853+
asyncio.run(run())
4854+
4855+
47554856
def test_wait_for_job_result_async_retries_overlong_numeric_bytes_status_errors():
47564857
async def run() -> None:
47574858
status_attempts = {"count": 0}
@@ -4789,6 +4890,43 @@ async def fetch_result() -> dict:
47894890
asyncio.run(run())
47904891

47914892

4893+
def test_wait_for_job_result_async_retries_overlong_bytes_like_status_errors():
4894+
async def run() -> None:
4895+
status_attempts = {"count": 0}
4896+
fetch_attempts = {"count": 0}
4897+
4898+
async def get_status() -> str:
4899+
status_attempts["count"] += 1
4900+
if status_attempts["count"] < 3:
4901+
raise HyperbrowserError(
4902+
"oversized status metadata",
4903+
status_code=array("B", [52, 48, 48, 48, 48, 48, 48]), # type: ignore[arg-type]
4904+
)
4905+
return "completed"
4906+
4907+
async def fetch_result() -> dict:
4908+
fetch_attempts["count"] += 1
4909+
return {"ok": True}
4910+
4911+
result = await wait_for_job_result_async(
4912+
operation_name="async wait helper status oversized bytes-like retries",
4913+
get_status=get_status,
4914+
is_terminal_status=lambda value: value == "completed",
4915+
fetch_result=fetch_result,
4916+
poll_interval_seconds=0.0001,
4917+
max_wait_seconds=1.0,
4918+
max_status_failures=5,
4919+
fetch_max_attempts=5,
4920+
fetch_retry_delay_seconds=0.0001,
4921+
)
4922+
4923+
assert result == {"ok": True}
4924+
assert status_attempts["count"] == 3
4925+
assert fetch_attempts["count"] == 1
4926+
4927+
asyncio.run(run())
4928+
4929+
47924930
def test_wait_for_job_result_async_does_not_retry_broken_executor_status_errors():
47934931
async def run() -> None:
47944932
status_attempts = {"count": 0}

0 commit comments

Comments
 (0)