Skip to content

Commit 85d9f9a

Browse files
committed
adding in test for run_in injection
Signed-off-by: Cortland Goffena <30168413+cmgoffena13@users.noreply.github.com>
1 parent bacf148 commit 85d9f9a

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/core/integration/test_model_kinds.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,48 @@ def _correlation_id_in_sqls(correlation_id: CorrelationId, mock_logger):
23322332
assert _correlation_id_in_sqls(correlation_id, mock_logger)
23332333

23342334

2335+
@time_machine.travel("2023-01-08 15:00:00 UTC")
2336+
def test_run_correlation_id(tmp_path: Path):
2337+
def _correlation_id_in_sqls(correlation_id: CorrelationId, mock_logger):
2338+
sqls = [call[0][0] for call in mock_logger.call_args_list]
2339+
return any(f"/* {correlation_id} */" in sql for sql in sqls)
2340+
2341+
run_id = "test_run_id"
2342+
ctx = Context(paths=[tmp_path], config=Config())
2343+
2344+
create_temp_file(
2345+
tmp_path,
2346+
Path("models", "test.sql"),
2347+
"""
2348+
MODEL (
2349+
name test.a,
2350+
kind INCREMENTAL_BY_TIME_RANGE (
2351+
time_column event_ts
2352+
),
2353+
cron '@daily',
2354+
start '2023-01-07'
2355+
);
2356+
SELECT 1 AS col, '2023-01-07' AS event_ts
2357+
""",
2358+
)
2359+
2360+
ctx.load()
2361+
ctx.plan(auto_apply=True, no_prompts=True)
2362+
2363+
with time_machine.travel("2023-01-09 00:00:00 UTC"):
2364+
with mock.patch(
2365+
"sqlmesh.core.context.analytics.collector.on_run_start", return_value=run_id
2366+
):
2367+
with mock.patch(
2368+
"sqlmesh.core.engine_adapter.base.EngineAdapter._log_sql"
2369+
) as mock_logger:
2370+
ctx.run()
2371+
2372+
correlation_id = CorrelationId.from_run_id(run_id)
2373+
assert str(correlation_id) == f"SQLMESH_RUN: {run_id}"
2374+
assert _correlation_id_in_sqls(correlation_id, mock_logger)
2375+
2376+
23352377
@time_machine.travel("2023-01-08 15:00:00 UTC")
23362378
def test_scd_type_2_regular_run_with_offset(init_and_plan_context: t.Callable):
23372379
context, plan = init_and_plan_context("examples/sushi")

0 commit comments

Comments
 (0)