Skip to content

Commit 00e806c

Browse files
authored
Fix failing integration tests that perform a real assessment (#2736)
## Changes Ensure 'assessment' workflow only runs minimal assessment in integration tests ### Linked issues None ### Functionality None ### Tests - [x] changed integration tests Co-authored-by: Eric Vergnaud <eric.vergnaud@databricks.com>
1 parent bbc07ea commit 00e806c

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

tests/integration/assessment/test_ext_hms.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import dataclasses
22
import datetime as dt
3-
import io
43

54
from databricks.labs.lsql.backends import CommandExecutionBackend
65
from databricks.sdk.service.iam import PermissionLevel
@@ -9,12 +8,11 @@
98
def test_running_real_assessment_job_ext_hms(
109
ws,
1110
installation_ctx,
11+
product_info,
1212
env_or_skip,
1313
make_cluster_policy,
1414
make_cluster_policy_permissions,
15-
make_notebook,
16-
make_job,
17-
make_dashboard,
15+
populate_for_linting,
1816
):
1917
cluster_id = env_or_skip('TEST_EXT_HMS_CLUSTER_ID')
2018
ext_hms_ctx = installation_ctx.replace(
@@ -41,14 +39,10 @@ def test_running_real_assessment_job_ext_hms(
4139
ext_hms_ctx.__dict__['include_object_permissions'] = [f"cluster-policies:{cluster_policy.policy_id}"]
4240
ext_hms_ctx.workspace_installation.run()
4341

42+
populate_for_linting(installation_ctx.installation)
43+
4444
# Under ideal circumstances this can take 10-16 minutes (depending on whether there are compute instances available
4545
# via the integration pool). Allow some margin to reduce spurious failures.
46-
notebook_path = make_notebook(content=io.BytesIO(b"import xyz"))
47-
job = make_job(notebook_path=notebook_path)
48-
installation_ctx.config.include_job_ids = [job.job_id]
49-
50-
dashboard = make_dashboard()
51-
installation_ctx.config.include_dashboard_ids = [dashboard.id]
5246
ext_hms_ctx.deployed_workflows.run_workflow("assessment", max_wait=dt.timedelta(minutes=25))
5347

5448
# assert the workflow is successful. the tasks on sql warehouse will fail so skip checking them

tests/integration/assessment/test_workflows.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import io
21
from datetime import timedelta
32

43
from databricks.sdk.errors import NotFound, InvalidParameterValue
@@ -8,7 +7,11 @@
87

98
@retried(on=[NotFound, InvalidParameterValue], timeout=timedelta(minutes=8))
109
def test_running_real_assessment_job(
11-
ws, installation_ctx, make_cluster_policy, make_cluster_policy_permissions, make_job, make_notebook, make_dashboard
10+
ws,
11+
installation_ctx,
12+
make_cluster_policy,
13+
make_cluster_policy_permissions,
14+
populate_for_linting,
1215
):
1316
ws_group, _ = installation_ctx.make_ucx_group()
1417
cluster_policy = make_cluster_policy()
@@ -20,12 +23,7 @@ def test_running_real_assessment_job(
2023
installation_ctx.__dict__['include_object_permissions'] = [f"cluster-policies:{cluster_policy.policy_id}"]
2124
installation_ctx.workspace_installation.run()
2225

23-
notebook_path = make_notebook(content=io.BytesIO(b"import xyz"))
24-
job = make_job(notebook_path=notebook_path)
25-
installation_ctx.config.include_job_ids = [job.job_id]
26-
27-
dashboard = make_dashboard()
28-
installation_ctx.config.include_dashboard_ids = [dashboard.id]
26+
populate_for_linting(installation_ctx.installation)
2927

3028
installation_ctx.deployed_workflows.run_workflow("assessment")
3129
assert installation_ctx.deployed_workflows.validate_step("assessment")

tests/integration/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
import json
23
from collections.abc import Callable, Generator
34
import functools
@@ -9,11 +10,15 @@
910
from functools import cached_property
1011
import shutil
1112
import subprocess
13+
from pathlib import Path
14+
1215
import pytest # pylint: disable=wrong-import-order
16+
import yaml
1317
from databricks.labs.blueprint.commands import CommandExecutor
1418
from databricks.labs.blueprint.entrypoint import is_in_debug
1519
from databricks.labs.blueprint.installation import Installation, MockInstallation
1620
from databricks.labs.blueprint.parallel import Threads
21+
from databricks.labs.blueprint.paths import WorkspacePath
1722
from databricks.labs.blueprint.tui import MockPrompts
1823
from databricks.labs.blueprint.wheels import ProductInfo
1924
from databricks.labs.lsql.backends import SqlBackend
@@ -1175,3 +1180,25 @@ def _run(command: str) -> str:
11751180
except ValueError as err:
11761181
logger.debug(f"pytest_ignore_collect: error: {err}")
11771182
return False
1183+
1184+
1185+
@pytest.fixture
1186+
def populate_for_linting(ws, make_random, make_job, make_notebook, make_query, make_dashboard, watchdog_purge_suffix):
1187+
def populate_workspace(installation):
1188+
# keep linting scope to minimum to avoid test timeouts
1189+
path = Path(installation.install_folder()) / f"dummy-{make_random(4)}-{watchdog_purge_suffix}"
1190+
notebook_path = make_notebook(path=path, content=io.BytesIO(b"spark.read.parquet('dbfs://mnt/foo/bar')"))
1191+
job = make_job(notebook_path=notebook_path)
1192+
query = make_query(sql_query='SELECT * from parquet.`dbfs://mnt/foo/bar`')
1193+
dashboard = make_dashboard(query=query)
1194+
# can't use installation.load(WorkspaceConfig)/installation.save() because they populate empty credentials
1195+
config_path = WorkspacePath(ws, installation.install_folder()) / "config.yml"
1196+
text = config_path.read_text()
1197+
config = yaml.safe_load(text)
1198+
config["include_job_ids"] = [job.job_id]
1199+
config["include_dashboard_ids"] = [dashboard.id]
1200+
text = yaml.dump(config)
1201+
config_path.unlink()
1202+
config_path.write_text(text)
1203+
1204+
return populate_workspace

0 commit comments

Comments
 (0)