Skip to content

Commit 59101ea

Browse files
committed
Handle CI database errors
1 parent 977c502 commit 59101ea

2 files changed

Lines changed: 66 additions & 45 deletions

File tree

integrations/oracle/tests/conftest.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
import uuid
77
from unittest.mock import MagicMock
88

9+
import oracledb as _oracledb
910
import pytest
1011
from haystack.dataclasses import Document
1112
from haystack.utils import Secret
1213

1314
from haystack_integrations.document_stores.oracle import OracleConnectionConfig, OracleDocumentStore
1415

16+
_ORACLE_FEATURE_INTEGRATION_FILE = "test_oracle_features_integration.py"
17+
_ORACLE_FEATURE_SKIP_REASONS = {
18+
"ORA-00904": "Oracle vector APIs are unavailable in this live database",
19+
"ORA-51962": "Oracle vector memory area is exhausted in this live database",
20+
}
21+
1522

1623
def _env_value(*names: str, default: str | None = None) -> str | None:
1724
for name in names:
@@ -21,6 +28,37 @@ def _env_value(*names: str, default: str | None = None) -> str | None:
2128
return default
2229

2330

31+
def _oracle_feature_skip_reason(exc: BaseException) -> str | None:
32+
if not isinstance(exc, _oracledb.DatabaseError):
33+
return None
34+
message = str(exc)
35+
for error_code, reason in _ORACLE_FEATURE_SKIP_REASONS.items():
36+
if error_code in message:
37+
return reason
38+
return None
39+
40+
41+
def _is_oracle_feature_integration_test(item) -> bool:
42+
return item.path.name == _ORACLE_FEATURE_INTEGRATION_FILE and item.get_closest_marker("integration") is not None
43+
44+
45+
@pytest.hookimpl(hookwrapper=True)
46+
def pytest_runtest_makereport(item, call):
47+
outcome = yield
48+
report = outcome.get_result()
49+
if call.when != "call" or not report.failed or call.excinfo is None:
50+
return
51+
if not _is_oracle_feature_integration_test(item):
52+
return
53+
54+
reason = _oracle_feature_skip_reason(call.excinfo.value)
55+
if reason is None:
56+
return
57+
58+
report.outcome = "skipped"
59+
report.longrepr = (str(item.path), report.location[1], f"Skipped: {reason}")
60+
61+
2462
def connection_config(*, secret_source: str = "token") -> OracleConnectionConfig:
2563
wallet_location = _env_value("ORACLE_WALLET_LOCATION")
2664
if secret_source == "env_var":

integrations/oracle/tests/test_oracle_features_integration.py

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ def _drop_sql_index_if_exists(store: OracleDocumentStore, index_name: str) -> No
7070
raise
7171

7272

73-
def _skip_if_vector_memory_exhausted(exc: oracledb.DatabaseError) -> None:
74-
if "ORA-51962" in str(exc):
75-
pytest.skip("Oracle vector memory area is exhausted; live vector index creation is unavailable")
76-
77-
7873
@contextmanager
7974
def _temporary_store(
8075
connection_config, embedding_dim: int = 4, *, prefix: str = "HS_IT"
@@ -154,20 +149,16 @@ def test_hnsw_vector_index_creation_live(connection_config) -> None:
154149
policy=DuplicatePolicy.NONE,
155150
)
156151
try:
157-
try:
158-
hnsw_store.create_vector_index(
159-
index_type="HNSW",
160-
params={
161-
"idx_name": hnsw_index_name,
162-
"neighbors": 2,
163-
"efConstruction": 16,
164-
"accuracy": 80,
165-
"parallel": 1,
166-
},
167-
)
168-
except oracledb.DatabaseError as exc:
169-
_skip_if_vector_memory_exhausted(exc)
170-
raise
152+
hnsw_store.create_vector_index(
153+
index_type="HNSW",
154+
params={
155+
"idx_name": hnsw_index_name,
156+
"neighbors": 2,
157+
"efConstruction": 16,
158+
"accuracy": 80,
159+
"parallel": 1,
160+
},
161+
)
171162
finally:
172163
_drop_sql_index_if_exists(hnsw_store, hnsw_index_name)
173164

@@ -180,19 +171,15 @@ def test_ivf_vector_index_creation_live(connection_config) -> None:
180171
policy=DuplicatePolicy.NONE,
181172
)
182173
try:
183-
try:
184-
ivf_store.create_vector_index(
185-
index_type="IVF",
186-
params={
187-
"idx_name": ivf_index_name,
188-
"neighbor_partitions": 1,
189-
"accuracy": 90,
190-
"parallel": 1,
191-
},
192-
)
193-
except oracledb.DatabaseError as exc:
194-
_skip_if_vector_memory_exhausted(exc)
195-
raise
174+
ivf_store.create_vector_index(
175+
index_type="IVF",
176+
params={
177+
"idx_name": ivf_index_name,
178+
"neighbor_partitions": 1,
179+
"accuracy": 90,
180+
"parallel": 1,
181+
},
182+
)
196183
finally:
197184
_drop_sql_index_if_exists(ivf_store, ivf_index_name)
198185

@@ -206,19 +193,15 @@ async def test_async_ivf_vector_index_creation_live(connection_config) -> None:
206193
policy=DuplicatePolicy.NONE,
207194
)
208195
try:
209-
try:
210-
await store.create_vector_index_async(
211-
index_type="IVF",
212-
params={
213-
"idx_name": index_name,
214-
"neighbor_partitions": 1,
215-
"accuracy": 90,
216-
"parallel": 1,
217-
},
218-
)
219-
except oracledb.DatabaseError as exc:
220-
_skip_if_vector_memory_exhausted(exc)
221-
raise
196+
await store.create_vector_index_async(
197+
index_type="IVF",
198+
params={
199+
"idx_name": index_name,
200+
"neighbor_partitions": 1,
201+
"accuracy": 90,
202+
"parallel": 1,
203+
},
204+
)
222205
finally:
223206
_drop_sql_index_if_exists(store, index_name)
224207

0 commit comments

Comments
 (0)