Skip to content

Commit

Permalink
Fix minor test bug for WPM (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-db authored Dec 7, 2023
2 parents 67c8f52 + 6e322f7 commit 004ca00
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/databricks/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def _log_usage(self, node: Optional[ResultNode]) -> None:
else:
logger.debug(
f"On thread {self.thread_identifier}: {node.relation_name} "
"using compute resource '{self.compute_name}'."
f"using compute resource '{self.compute_name}'."
)
else:
logger.debug(f"Thread {self.thread_identifier} using default compute resource.")
Expand Down
7 changes: 6 additions & 1 deletion tests/functional/adapter/long_sessions/test_long_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from dbt.tests import util
from tests.functional.adapter.long_sessions import fixtures

with mock.patch.dict(os.environ, {"DBT_DATABRICKS_LONG_SESSIONS": "true"}):
with mock.patch.dict(
os.environ,
{"DBT_DATABRICKS_LONG_SESSIONS": "true", "DBT_DATABRICKS_CONNECTOR_LOG_LEVEL": "DEBUG"},
):
import dbt.adapters.databricks.connections # noqa


Expand Down Expand Up @@ -45,6 +48,7 @@ def test_long_sessions(self, project):
assert open_count == (n_threads + 1)


@pytest.mark.skip("May fail non-deterministically due to issue in dbt test framework.")
class TestLongSessionsMultipleCompute:
args_formatter = ""

Expand Down Expand Up @@ -81,6 +85,7 @@ def test_long_sessions(self, project):
assert open_count == 3


@pytest.mark.skip("May fail non-deterministically due to issue in dbt test framework.")
class TestLongSessionsIdleCleanup(TestLongSessionsMultipleCompute):
args_formatter = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ def models(self):
"special": d,
}

@pytest.fixture(scope="class")
def profile_dir(self, profiles_root):
return str(profiles_root)


class BaseSpecifyingCompute(BaseWarehousePerModel):
"""Base class for testing various ways to specify a warehouse."""

def test_wpm(self, project):
util.run_dbt(["seed"])
def test_wpm(self, project, profile_dir):
util.run_dbt(["seed", "--profiles-dir", profile_dir])
models = project.test_config.get("model_names")
for model_name in models:
# Since the profile doesn't define a compute resource named 'alternate_warehouse'
# we should fail with an error if the warehouse specified for the model is
# correctly handled.
res = util.run_dbt(["run", "--select", model_name], expect_pass=False)
res = util.run_dbt(
["run", "--select", model_name, "--profiles-dir", profile_dir],
expect_pass=False,
)
msg = res.results[0].message
assert "Compute resource alternate_warehouse does not exist" in msg
assert model_name in msg
Expand Down Expand Up @@ -85,6 +92,7 @@ def test_config(self):
return {"model_names": ["target4"]}


@pytest.mark.skip("May fail non-deterministically due to issue in dbt test framework.")
class TestWarehousePerModel(BaseWarehousePerModel):
@pytest.fixture(scope="class")
def profiles_config_update(self, dbt_profile_target):
Expand All @@ -109,15 +117,17 @@ def snapshots(self):
"target_snap.sql": fixtures.target_snap,
}

def test_wpm(self, project):
_, log = util.run_dbt_and_capture(["--debug", "seed"])
def test_wpm(self, project, profile_dir):
_, log = util.run_dbt_and_capture(["--debug", "seed", "--profiles-dir", profile_dir])
assert "`source` using compute resource 'alternate_warehouse2'" in log

_, log = util.run_dbt_and_capture(["--debug", "run", "--select", "target", "target3"])
_, log = util.run_dbt_and_capture(
["--debug", "run", "--select", "target", "target3", "--profiles-dir", profile_dir]
)
assert "`target` using compute resource 'alternate_warehouse'" in log
assert "`target3` using default compute resource" in log

_, log = util.run_dbt_and_capture(["--debug", "snapshot"])
_, log = util.run_dbt_and_capture(["--debug", "snapshot", "--profiles-dir", profile_dir])
assert "`target_snap` using compute resource 'alternate_warehouse3'" in log

util.check_relations_equal(project.adapter, ["target", "source"])

0 comments on commit 004ca00

Please sign in to comment.