Skip to content

Commit 22ecb47

Browse files
authored
test(location): rebuild past the changed-build order skew before replanning (#1577)
The served-location replan test failed intermittently in CI: after a rebuild and its sync, the location reported daily_orders, order_count and orders as changed instead of nothing. `--changed` compares a relation with each of its executions within 5 s of its newest, so a rebuild that starts within 5 s of the previous build still reports that build's edit and its consumers' inputs as unknown. Locally the rebuild started 5.6 s after the first build; a faster runner started it inside the window. With the window widened to 10 s the test failed every time with exactly the CI report. The test now starts the rebuild at least the order skew after the first build returned. The publication tests share one ORDER_SKEW_SECONDS instead of each defining it.
1 parent 0ac57cb commit 22ecb47

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎tests/integration/src/sqlbuild/compiler/compiled_project/publication/helpers.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,9 @@ def tagged_model(name: str, tags: str) -> str:
15671567
)
15681568

15691569

1570+
# `--changed` compares a relation with each of its executions this close to its newest, so a
1571+
# rebuild sooner than this after a build still reports that build's edits and inputs.
1572+
ORDER_SKEW_SECONDS: float = 5.2
15701573
CHANGED_FIXTURE: Path = Path("benchmarks/duckshop/edge_cases/changed_builds")
15711574
CHANGED_JOB: str = (
15721575
'name = "changed_orders_job"\n'

‎tests/integration/src/sqlbuild/compiler/compiled_project/publication/test_changed.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
ChangedJobTestCase,
1212
)
1313
from tests.integration.src.sqlbuild.compiler.compiled_project.publication.helpers import (
14+
ORDER_SKEW_SECONDS,
1415
changed_job_files,
1516
duckdb_rows,
1617
request_job_run,
1718
scheduled_worker,
1819
sqlite_rows,
1920
)
2021

21-
ORDER_SKEW_SECONDS: float = 5.2
2222
EXPECTED_CHANGED_RUNS: tuple[tuple[str, frozenset[str], dict[str, int]], ...] = (
2323
("first run", frozenset({"stg_orders", "stg_customers", "customer_orders"}), {"success": 3}),
2424
("nothing changed", frozenset(), {"success": 3}),

‎tests/integration/src/sqlbuild/compiler/compiled_project/publication/test_plan_preview.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sqlite3
66
import subprocess
77
import sys
8+
import time
89
from contextlib import closing
910
from pathlib import Path
1011
from textwrap import dedent
@@ -28,6 +29,7 @@
2829
request_warehouse_sync,
2930
)
3031
from tests.integration.src.sqlbuild.compiler.compiled_project.publication.helpers import (
32+
ORDER_SKEW_SECONDS,
3133
changed_build_and_plan_from_copy,
3234
changed_build_report,
3335
changed_runs,
@@ -386,6 +388,7 @@ def test_given_a_served_location_when_syncs_complete_then_it_replans_only_after_
386388
write_files(project_dir=project, files=_PROJECT_FILES)
387389
built: subprocess.CompletedProcess[str] = run_sqb(project, "build", "--target", "development")
388390
assert built.returncode == 0, built.stderr
391+
built_at: float = time.monotonic()
389392
edited: str = _PROJECT_FILES["models/order_count.sql"].replace(*test_case.edit)
390393
write_files(project_dir=project, files={"models/order_count.sql": edited})
391394
control: Path = tmp_path / "control/.sqlbuild/control.sqlite3"
@@ -433,6 +436,7 @@ def changed_build() -> dict[str, list[str]]:
433436
_ = wait_for_location_work(api, request_plan(control, ["model:orders"]), location, log)
434437
assert log.read_text().count(_PLANNED) == 1, "a sync that applied nothing keeps the count"
435438

439+
time.sleep(max(0.0, built_at + ORDER_SKEW_SECONDS - time.monotonic()))
436440
rebuilt: subprocess.CompletedProcess[str] = run_sqb(
437441
project, "build", "--target", "development"
438442
)

0 commit comments

Comments
 (0)