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 24, 2024
1 parent ae2744a commit 0f1f031
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tosfs/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

from tosfs.exceptions import TosfsError

CONFLICT_CODE = "409"
TOO_MANY_REQUESTS_CODE = "429"
SERVICE_UNAVAILABLE = "503"
CONFLICT_CODE = 409
TOO_MANY_REQUESTS_CODE = 429
SERVICE_UNAVAILABLE = 503

TOS_SERVER_RETRYABLE_STATUS_CODES = {
CONFLICT_CODE,
TOO_MANY_REQUESTS_CODE,
"500", # INTERNAL_SERVER_ERROR,
500, # INTERNAL_SERVER_ERROR,
SERVICE_UNAVAILABLE,
}

Expand Down
55 changes: 55 additions & 0 deletions tosfs/tests/test_retry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ByteDance Volcengine EMR, Copyright 2024.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest.mock import Mock

import pytest
import requests
from tos.exceptions import TosServerError
from tos.http import Response

from tosfs.retry import is_retryable_exception

mock_resp = Mock(spec=requests.Response)

mock_resp.status_code = 429
mock_resp.headers = {"content-length": "123", "x-tos-request-id": "test-id"}
mock_resp.iter_content = Mock(return_value=[b"chunk1", b"chunk2", b"chunk3"])
mock_resp.json = Mock(return_value={"key": "value"})

response = Response(mock_resp)


@pytest.mark.parametrize(
("exception", "expected"),
[
(
TosServerError(
response,
"Exceed account external rate limit. Too much throughput in a "
"short period of time, please slow down.",
"ExceedAccountExternalRateLimit",
"KMnpaCqRoqUCpepbpAbTtCFGiekNmffA",
"",
"0004-00000001",
),
True,
)
],
)
def test_is_retry_exception(
exception,
expected,
):
assert is_retryable_exception(exception) == expected

0 comments on commit 0f1f031

Please sign in to comment.