Skip to content

Commit 7ac0dc6

Browse files
authored
Adding smoke test for batch ingestion throwing exception (#12453)
1 parent cb47577 commit 7ac0dc6

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

smoke-test/tests/restli/restli_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def make_mcp(self) -> MetadataChangeProposalClass:
5151
return mcp
5252

5353

54-
@pytest.fixture(scope="module")
54+
@pytest.fixture(scope="module", autouse=True)
5555
def ingest_cleanup_data(auth_session, graph_client, request):
5656
yield
5757
delete_urns(graph_client, generated_urns)

smoke-test/tests/restli/test_restli_batch_ingestion.py

+53-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
import datahub.metadata.schema_classes as models
67
from datahub.emitter.mce_builder import make_dashboard_urn
78
from datahub.emitter.mcp import MetadataChangeProposalWrapper
89
from datahub.emitter.serialization_helper import pre_json_transform
@@ -12,14 +13,15 @@
1213
ChangeAuditStampsClass,
1314
DashboardInfoClass,
1415
)
16+
from datahub.metadata.urns import MlModelUrn
1517
from tests.consistency_utils import wait_for_writes_to_sync
1618
from tests.restli.restli_test import MetadataChangeProposalInvalidWrapper
1719
from tests.utils import delete_urns
1820

1921
generated_urns: List[str] = []
2022

2123

22-
@pytest.fixture(scope="module")
24+
@pytest.fixture(scope="module", autouse=True)
2325
def ingest_cleanup_data(auth_session, graph_client, request):
2426
yield
2527
delete_urns(graph_client, generated_urns)
@@ -84,6 +86,29 @@ def _create_invalid_dashboard_mcp() -> MetadataChangeProposalClass:
8486
return mcp_invalid.make_mcp()
8587

8688

89+
def _create_invalid_dataset_mcps() -> List[MetadataChangeProposalWrapper]:
90+
dataset_urn = "urn:li:dataset:(urn:li:dataPlatform:kafka,my_dataset,PROD)"
91+
model_urn = MlModelUrn("mlflow", "my_model", "PROD").urn()
92+
bad_mcps = [
93+
MetadataChangeProposalWrapper(
94+
entityUrn=dataset_urn,
95+
aspect=models.StatusClass(removed=False),
96+
),
97+
MetadataChangeProposalWrapper(
98+
entityUrn=dataset_urn,
99+
aspect=models.UpstreamLineageClass(
100+
upstreams=[
101+
models.UpstreamClass(
102+
dataset=model_urn,
103+
type=models.DatasetLineageTypeClass.TRANSFORMED,
104+
)
105+
]
106+
),
107+
),
108+
]
109+
return bad_mcps
110+
111+
87112
def test_restli_batch_ingestion_sync(graph_client):
88113
# Positive Test (all valid MetadataChangeProposal)
89114
mcps = _create_valid_dashboard_mcps()
@@ -133,3 +158,30 @@ def test_restli_batch_ingestion_async(graph_client):
133158
assert aspect.title == "Dummy Title For Testing"
134159
assert aspect.description == "Dummy Description For Testing"
135160
assert aspect.lastModified is not None
161+
162+
163+
def test_restli_batch_ingestion_exception_sync(graph_client):
164+
"""
165+
Test Batch ingestion when an exception occurs in sync mode
166+
"""
167+
bad_mcps = _create_invalid_dataset_mcps()
168+
generated_urns.extend([mcp.entityUrn for mcp in bad_mcps if mcp.entityUrn])
169+
170+
try:
171+
graph_client.emit_mcps(bad_mcps, async_flag=False)
172+
raise AssertionError("should have thrown an exception")
173+
except Exception as e:
174+
if isinstance(e, AssertionError):
175+
raise e
176+
print(f"Error emitting MCPs due to {e}")
177+
178+
179+
def test_restli_batch_ingestion_exception_async(graph_client):
180+
"""
181+
Test Batch ingestion when an exception occurs in async mode
182+
"""
183+
bad_mcps = _create_invalid_dataset_mcps()
184+
generated_urns.extend([mcp.entityUrn for mcp in bad_mcps if mcp.entityUrn])
185+
# TODO expectation is that it throws exception, but it doesn't currently.this test case need to change after fix.
186+
ret = graph_client.emit_mcps(bad_mcps, async_flag=True)
187+
assert ret >= 0

0 commit comments

Comments
 (0)