Skip to content

Commit 673641a

Browse files
fix: address CodeRabbit review comments
- Mock time.sleep in 5 retry tests to prevent real exponential backoff delays - Update test_is_retryable_server_error docstring to mention transient 5xx errors Co-authored-by: Sisyphus <[email protected]>
1 parent ccc9d3f commit 673641a

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

tests/unit/core/api/test_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ class TestRetryLogic:
690690
"""Unit tests for retry logic in APIClient."""
691691

692692
def test_is_retryable_server_error(self, mocker: MockerFixture) -> None:
693-
"""Test _is_retryable_server_error identifies 429 and 5xx errors."""
693+
"""Test _is_retryable_server_error identifies 429 and transient 5xx errors."""
694694
resp_429 = mocker.Mock(status_code=429)
695695
assert _is_retryable_server_error(
696696
httpx.HTTPStatusError("", request=mocker.Mock(), response=resp_429)
@@ -727,6 +727,7 @@ def test_standard_query_retries_on_429_then_succeeds(
727727
self, basic_api_config_query_endpoint: APIConfig, mocker: MockerFixture
728728
) -> None:
729729
"""Test standard query retries on 429 error and then succeeds on retry."""
730+
mocker.patch("time.sleep")
730731
mock_response_429 = mocker.Mock(status_code=429)
731732
mock_response_429.raise_for_status.side_effect = httpx.HTTPStatusError(
732733
"429 error", request=mocker.Mock(), response=mock_response_429
@@ -757,6 +758,7 @@ def test_streaming_query_retries_on_429_then_succeeds(
757758
self, basic_api_config_streaming_endpoint: APIConfig, mocker: MockerFixture
758759
) -> None:
759760
"""Test streaming query retries on 429 error and then succeeds on retry."""
761+
mocker.patch("time.sleep")
760762
mock_stream_429 = mocker.Mock(status_code=429, request=mocker.Mock())
761763
mock_context_429 = mocker.MagicMock()
762764
mock_context_429.__enter__.return_value = mock_stream_429
@@ -791,6 +793,7 @@ def test_query_raises_api_error_after_max_retries(
791793
self, basic_api_config_query_endpoint: APIConfig, mocker: MockerFixture
792794
) -> None:
793795
"""Test query raises APIError after exhausting retry attempts."""
796+
mocker.patch("time.sleep")
794797
basic_api_config_query_endpoint.num_retries = 3
795798

796799
mock_response_429 = mocker.Mock(status_code=429)
@@ -818,6 +821,7 @@ def test_standard_query_retries_on_502_then_succeeds(
818821
self, basic_api_config_query_endpoint: APIConfig, mocker: MockerFixture
819822
) -> None:
820823
"""Test standard query retries on 502 error and succeeds on retry."""
824+
mocker.patch("time.sleep")
821825
mock_response_502 = mocker.Mock(status_code=502, text="Bad gateway")
822826
mock_response_502.raise_for_status.side_effect = httpx.HTTPStatusError(
823827
"502 error", request=mocker.Mock(), response=mock_response_502

tests/unit/core/api/test_client_infer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def test_infer_query_retries_on_429(
192192
self, basic_api_config_infer_endpoint: APIConfig, mocker: MockerFixture
193193
) -> None:
194194
"""Test infer query retries on 429 then succeeds."""
195+
mocker.patch("time.sleep")
195196
mock_response_429 = mocker.Mock(status_code=429)
196197
mock_response_429.raise_for_status.side_effect = httpx.HTTPStatusError(
197198
"429 error", request=mocker.Mock(), response=mock_response_429

0 commit comments

Comments
 (0)