Skip to content

Commit

Permalink
Add test cases for stability
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Sep 25, 2024
1 parent f408ce1 commit 9b64b78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tosfs/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,14 @@ def _is_retryable_tos_server_exception(e: TosError) -> bool:


def _is_retryable_tos_client_exception(e: TosError) -> bool:
return isinstance(e, TosClientError) and any(
isinstance(e.cause, excp) for excp in TOS_CLIENT_RETRYABLE_EXCEPTIONS
)
if isinstance(e, TosClientError):
cause = e.cause
while cause is not None:
for excp in TOS_CLIENT_RETRYABLE_EXCEPTIONS:
if isinstance(cause, excp):
return True
cause = getattr(cause, "cause", None)
return False


def _get_sleep_time(err: TosError, retry_count: int) -> float:
Expand Down
20 changes: 20 additions & 0 deletions tosfs/tests/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@
),
True,
),
(
TosClientError(
"{'message': 'http request timeout', "
"'case': \"('Connection aborted.', "
"ConnectionResetError(104, 'Connection reset by peer'))\", "
"'request_url': "
"'http://proton-ci.tos-cn-beijing.volces.com/"
"nHnbR/yAlen'}",
TosClientError(
"http request timeout",
ConnectionError(
ProtocolError(
"Connection aborted.",
ConnectionResetError(104, "Connection reset by peer"),
)
),
),
),
True,
),
],
)
def test_is_retry_exception(
Expand Down

0 comments on commit 9b64b78

Please sign in to comment.