Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ingestion/tests/integration/ometa/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from metadata.generated.schema.entity.services.connections.database.mysqlConnection import (
MysqlConnection,
MySQLType,
)
from metadata.generated.schema.entity.services.dashboardService import DashboardService
from metadata.generated.schema.entity.services.databaseService import DatabaseService
Expand Down Expand Up @@ -237,7 +238,10 @@ def workflow(metadata, database_service, mysql_container):
METADATA_INGESTION_CONFIG_TEMPLATE.format(
type="mysql",
service_name=service_name,
# `type` must be set explicitly: the dump excludes unset fields, and without the
# discriminator the untagged DatabaseConnection union can resolve to another connector.
service_config=MysqlConnection(
type=MySQLType.Mysql,
username=mysql_container.username,
authType=BasicAuth(
password=mysql_container.password,
Expand Down
18 changes: 8 additions & 10 deletions ingestion/tests/integration/usage/test_sample_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ def test_join_count(self):
"""
Check the join count
"""
# sample_data is a BigQuery service, whose usage resolution rewrites each
# query reference to the matched table's FQN without the service prefix.
expected_result = {
"shopify.raw_product_catalog": 6,
"dim_customer": 4,
"fact_order": 4,
"shopify.fact_sale": 5,
"shopify.raw_customer": 11,
"ecommerce_db.shopify.raw_product_catalog": 6,
"ecommerce_db.shopify.dim_customer": 4,
"ecommerce_db.shopify.fact_order": 4,
"ecommerce_db.shopify.fact_sale": 5,
"ecommerce_db.shopify.raw_customer": 11,
}
config_dict = json.loads(config)
config_dict["source"]["serviceConnection"]["config"]["connectionOptions"]["sampleDataFolder"] = (
Expand All @@ -94,9 +96,5 @@ def test_join_count(self):
for key, value in workflow.steps[1].table_usage.items():
table_usage_map[key[0]] = value.count

for table_name, expected_count in expected_result.items():
try:
self.assertEqual(table_usage_map[table_name], expected_count)
except KeyError:
self.assertTrue(False)
assert {name: table_usage_map.get(name) for name in expected_result} == expected_result
workflow.stop()
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# limitations under the License.
"""Unit tests for Alation Sink writes: batching and waiting on Alation's background jobs."""

from types import SimpleNamespace
from unittest.mock import MagicMock, patch

import requests
Expand All @@ -28,6 +29,12 @@
CLIENT_MODULE = "metadata.ingestion.source.metadata.alationsink.client"


def _fake_clock(*ticks: float):
"""Patch the client module's `time` binding, not `time.monotonic` itself: the global attribute
is shared by every thread, and a background thread from another test would consume the ticks"""
return patch(f"{CLIENT_MODULE}.time", SimpleNamespace(monotonic=iter(ticks).__next__))


def _client(*jobs: dict) -> AlationSinkClient:
"""Client whose writes are accepted as job 7, and whose job polls answer `jobs` in order"""
client = AlationSinkClient(AlationSinkConnection(hostPort="http://alation", authType={"accessToken": "token"}))
Expand Down Expand Up @@ -87,11 +94,9 @@ def test_job_still_running_at_timeout_is_a_failure():
def test_no_poll_starts_after_the_deadline():
client = _client({"status": "running"}, {"status": "successful", "result": []})
# deadline = 0 + 10; first check passes at 0, the post-sleep check lands past the deadline
clock = iter([0, 0, 9.8, 11])

with (
patch(f"{CLIENT_MODULE}.JOB_TIMEOUT_SECONDS", 10),
patch(f"{CLIENT_MODULE}.time.monotonic", lambda: next(clock)),
_fake_clock(0, 0, 9.8, 11),
):
errors = client.write_entities(39, _columns(3))

Expand Down Expand Up @@ -132,11 +137,9 @@ def test_permanent_poll_failure_stops_polling():

def test_timeout_reports_the_last_poll_error():
client = _client(_http_error(503), _http_error(502))
clock = iter([0, 0, 1, 1, 1, 11])

with (
patch(f"{CLIENT_MODULE}.JOB_TIMEOUT_SECONDS", 10),
patch(f"{CLIENT_MODULE}.time.monotonic", lambda: next(clock)),
_fake_clock(0, 0, 1, 1, 1, 11),
):
errors = client.write_entities(39, _columns(3))

Expand Down
Loading