Skip to content

Commit 1fba341

Browse files
committed
fix: add test for run loads materializations only once
Signed-off-by: lafirm <136463254+lafirm@users.noreply.github.com>
1 parent e6b3f16 commit 1fba341

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎tests/core/integration/test_aux_commands.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ def test_table_name(init_and_plan_context: t.Callable):
8888
)
8989

9090

91+
@time_machine.travel("2023-01-08 15:00:00 UTC")
92+
def test_run_loads_materializations_once(init_and_plan_context: t.Callable, mocker: MockerFixture):
93+
"""Verify janitor and run dispatch loading while loaders execute only once."""
94+
context, plan = init_and_plan_context("examples/sushi")
95+
context.apply(plan)
96+
load_dispatch_spy = mocker.spy(context, "_load_materializations")
97+
loader_spies = [mocker.spy(loader, "load_materializations") for loader in context._loaders]
98+
assert loader_spies
99+
assert context._materializations_loaded is True
100+
101+
# Reset the guard to exercise lazy loading through run's janitor and scheduler paths.
102+
context._materializations_loaded = False
103+
context.run(skip_janitor=False)
104+
105+
# The janitor and run each call the context wrapper; the second call is guarded.
106+
assert load_dispatch_spy.call_count == 2
107+
108+
# Only the janitor's first dispatch reaches the loaders.
109+
for loader_spy in loader_spies:
110+
assert loader_spy.call_count == 1
111+
112+
91113
def test_janitor_loads_materialization(tmp_path: Path):
92114
config_file_path = Path("config.yaml")
93115
database = tmp_path / "janitor_test.duckdb"

0 commit comments

Comments
 (0)