Skip to content

Commit 043890f

Browse files
committed
test NEXUS-817: fixed retries in tests
1 parent 7ccec6b commit 043890f

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

_test_contract/conftest.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,66 @@
44

55
import pytest
66

7-
from unstructured_client import UnstructuredClient
7+
from unstructured_client import UnstructuredClient, utils
88

99
FAKE_API_KEY = "91pmLBeETAbXCpNylRsLq11FdiZPTk"
1010

11+
1112
@pytest.fixture(scope="module")
1213
def platform_client(platform_api_url) -> UnstructuredClient:
14+
# settings the retry config to always try 3 times after a fail = 4 requests sent
1315
_client = UnstructuredClient(
1416
api_key_auth=FAKE_API_KEY,
1517
server_url=platform_api_url,
18+
retry_config=utils.RetryConfig(
19+
"backoff", utils.BackoffStrategy(
20+
initial_interval=3000,
21+
max_interval=3000,
22+
exponent=1.0,
23+
max_elapsed_time=8000
24+
),
25+
retry_connection_errors=True
26+
)
1627
)
1728
yield _client
1829

30+
1931
@pytest.fixture(scope="module")
2032
def serverless_client(serverless_api_url) -> UnstructuredClient:
33+
# settings the retry config to always try 3 times after a fail = 4 requests sent
2134
_client = UnstructuredClient(
2235
api_key_auth=FAKE_API_KEY,
23-
server_url=serverless_api_url
36+
server_url=serverless_api_url,
37+
retry_config = utils.RetryConfig(
38+
"backoff", utils.BackoffStrategy(
39+
initial_interval=3000,
40+
max_interval=3000,
41+
exponent=1.0,
42+
max_elapsed_time=8000
43+
),
44+
retry_connection_errors=True
45+
)
2446
)
2547
yield _client
2648

49+
2750
@pytest.fixture(autouse=True)
2851
def mock_sleep(mocker, freezer):
2952
sleep_mock = mocker.patch("time.sleep")
3053
sleep_mock.side_effect = lambda seconds: freezer.tick(timedelta(seconds=seconds))
3154
yield sleep_mock
3255

56+
3357
@pytest.fixture(scope="module")
3458
def platform_api_url():
3559
return "https://platform.unstructuredapp.io"
3660

61+
3762
@pytest.fixture(scope="module")
3863
def serverless_api_url():
3964
return "https://api.unstructuredapp.io"
4065

66+
4167
@pytest.fixture(scope="module")
4268
def dummy_partitioned_text():
4369
return """[
@@ -82,8 +108,9 @@ def dummy_partitioned_text():
82108
}
83109
]"""
84110

111+
85112
@pytest.fixture(scope="module")
86113
def doc_path() -> Path:
87114
samples_path = Path(__file__).resolve().parents[1] / "_sample_docs"
88115
assert samples_path.exists()
89-
return samples_path
116+
return samples_path

_test_contract/platform_api/test_jobs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def test_get_job_error(httpx_mock, platform_client: UnstructuredClient, platform
119119
headers={"Content-Type": "application/json"},
120120
json={"detail": "Internal server error"},
121121
url=url,
122+
is_reusable=True,
122123
)
123124

124125
with pytest.raises(SDKError) as e:
@@ -132,7 +133,7 @@ def test_get_job_error(httpx_mock, platform_client: UnstructuredClient, platform
132133
assert e.value.message == "API error occurred"
133134

134135
requests = httpx_mock.get_requests()
135-
assert len(requests) == 1
136+
assert len(requests) == 4
136137
request = requests[0]
137138
assert request.method == "GET"
138139
assert request.url == url

_test_contract/test_retries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_partition_retries(
9090
requests = httpx_mock.get_requests()
9191
assert len(requests) == 3
9292
for request in requests:
93-
assert request.method == "POSt"
93+
assert request.method == "POST"
9494
assert request.url == url
9595

9696
assert len(partition_response.elements) > 0

0 commit comments

Comments
 (0)