Skip to content

Commit e9c0bf9

Browse files
Add non-ASCII byte status fallback regression coverage
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 5b6e0b9 commit e9c0bf9

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/test_polling.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,34 @@ async def get_status() -> str:
480480
asyncio.run(run())
481481

482482

483+
def test_poll_until_terminal_status_async_handles_non_ascii_byte_status_codes_as_retryable():
484+
async def run() -> None:
485+
attempts = {"count": 0}
486+
487+
async def get_status() -> str:
488+
attempts["count"] += 1
489+
if attempts["count"] < 3:
490+
raise HyperbrowserError(
491+
"non-ascii byte status code",
492+
status_code=b"\xff", # type: ignore[arg-type]
493+
)
494+
return "completed"
495+
496+
status = await poll_until_terminal_status_async(
497+
operation_name="async poll non-ascii byte status retries",
498+
get_status=get_status,
499+
is_terminal_status=lambda value: value == "completed",
500+
poll_interval_seconds=0.0001,
501+
max_wait_seconds=1.0,
502+
max_status_failures=5,
503+
)
504+
505+
assert status == "completed"
506+
assert attempts["count"] == 3
507+
508+
asyncio.run(run())
509+
510+
483511
def test_poll_until_terminal_status_retries_server_errors():
484512
attempts = {"count": 0}
485513

@@ -927,6 +955,29 @@ def operation() -> str:
927955
assert attempts["count"] == 3
928956

929957

958+
def test_retry_operation_handles_non_ascii_byte_status_codes_as_retryable():
959+
attempts = {"count": 0}
960+
961+
def operation() -> str:
962+
attempts["count"] += 1
963+
if attempts["count"] < 3:
964+
raise HyperbrowserError(
965+
"non-ascii byte status code",
966+
status_code=b"\xfe", # type: ignore[arg-type]
967+
)
968+
return "ok"
969+
970+
result = retry_operation(
971+
operation_name="sync retry non-ascii byte status code",
972+
operation=operation,
973+
max_attempts=5,
974+
retry_delay_seconds=0.0001,
975+
)
976+
977+
assert result == "ok"
978+
assert attempts["count"] == 3
979+
980+
930981
def test_retry_operation_rejects_awaitable_operation_result():
931982
async def async_operation() -> str:
932983
return "ok"

0 commit comments

Comments
 (0)