From 57e87eecaa03999ce5b85d014c0b5d5ddcd9641e Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Tue, 17 Nov 2026 05:45:10 +0000 Subject: [PATCH] test: make the Recall heartbeat planning setup and locked-store checks deterministic The ClickHouse invocations plan test gave recall_heartbeats a part with a setup row that set only invocation_id, so its start time defaulted to 1970. The table's TTL removes such a row as it is inserted and drops the empty part shortly after, so whenever the build wrote no heartbeat of its own the plan read nothing from the table. The setup row now starts now. The locked-store test also counts the work the locked build did: its closing notice reports dropped records and no failures, and after the lock is released only the other builds are recorded. --- .../main/clickhouse/test_clickhouse_recall_views.py | 6 ++++-- .../src/sqlbuild/cli/recall/_test_types.py | 2 ++ .../integration/src/sqlbuild/cli/recall/helpers.py | 1 + .../src/sqlbuild/cli/recall/test_local_recall.py | 13 +++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/e2e/src/sqlbuild/cli/commands/main/clickhouse/test_clickhouse_recall_views.py b/tests/e2e/src/sqlbuild/cli/commands/main/clickhouse/test_clickhouse_recall_views.py index b5f6aa8be2..b9913aa3e8 100644 --- a/tests/e2e/src/sqlbuild/cli/commands/main/clickhouse/test_clickhouse_recall_views.py +++ b/tests/e2e/src/sqlbuild/cli/commands/main/clickhouse/test_clickhouse_recall_views.py @@ -377,11 +377,13 @@ def test_given_one_invocation_lookup_when_planned_then_each_table_is_read_once_b assert run(project_dir, "build").returncode == 0 # A command that ends before its first heartbeat writes none, and ClickHouse plans a table # with no parts as a read of nothing, so give the heartbeats table a part before planning. + # The row starts now: an expired TTL would drop it on insert and its empty part soon after. execute_clickhouse_sql( config=clickhouse_e2e_config, statements=( - f"INSERT INTO {recall_database}.recall_heartbeats (invocation_id) " - "VALUES ('planning-setup')", + f"INSERT INTO {recall_database}.recall_heartbeats " + "(invocation_id, invocation_started_at, beat_at, stale_at) " + "VALUES ('planning-setup', now64(6), now64(6), now64(6))", ), ) sql: str = ( diff --git a/tests/integration/src/sqlbuild/cli/recall/_test_types.py b/tests/integration/src/sqlbuild/cli/recall/_test_types.py index c07441efee..15ca0d59cb 100644 --- a/tests/integration/src/sqlbuild/cli/recall/_test_types.py +++ b/tests/integration/src/sqlbuild/cli/recall/_test_types.py @@ -101,6 +101,8 @@ class HeldLockTestCase: builds_before_lock: int expected_exit_code: int expected_notice: str + expected_failed_records: int + expected_recorded_builds: int #: Far beyond the budget; only a build that waits for the lock itself reaches it. hang_guard_seconds: float diff --git a/tests/integration/src/sqlbuild/cli/recall/helpers.py b/tests/integration/src/sqlbuild/cli/recall/helpers.py index d88e972708..fd51e8e343 100644 --- a/tests/integration/src/sqlbuild/cli/recall/helpers.py +++ b/tests/integration/src/sqlbuild/cli/recall/helpers.py @@ -30,6 +30,7 @@ STOP_HANG_SECONDS: int = 120 EMPTY_RESULT: bytes = b'{"rows": []}' NUMBERED_LINE: re.Pattern[bytes] = re.compile(rb"^(\d+) std(?:out|err)$", re.MULTILINE) +INCOMPLETE_HISTORY: re.Pattern[str] = re.compile(r"incomplete \((\d+) dropped, (\d+) failed\)") PROJECT_TOML: str = ( 'name = "orders_shop"\n' 'adapter = "duckdb"\n' diff --git a/tests/integration/src/sqlbuild/cli/recall/test_local_recall.py b/tests/integration/src/sqlbuild/cli/recall/test_local_recall.py index 7c8f5eec54..d93b9e2447 100644 --- a/tests/integration/src/sqlbuild/cli/recall/test_local_recall.py +++ b/tests/integration/src/sqlbuild/cli/recall/test_local_recall.py @@ -33,6 +33,7 @@ EMITTED_STDERR, EMITTED_STDOUT, EMITTED_TAIL, + INCOMPLETE_HISTORY, MEBIBYTE, build_while_store_locked, build_with_failing_recall_notices, @@ -546,6 +547,8 @@ def test_given_a_successful_command_when_recorded_then_it_ends_completed( builds_before_lock=1, expected_exit_code=0, expected_notice="Recall delivery did not finish within the shutdown timeout", + expected_failed_records=0, + expected_recorded_builds=2, hang_guard_seconds=60.0, ), HeldLockTestCase( @@ -554,6 +557,8 @@ def test_given_a_successful_command_when_recorded_then_it_ends_completed( builds_before_lock=0, expected_exit_code=0, expected_notice="Recall delivery did not finish within the shutdown timeout", + expected_failed_records=0, + expected_recorded_builds=1, hang_guard_seconds=60.0, ), ], @@ -568,10 +573,18 @@ def test_given_a_locked_store_when_building_then_it_gives_up_at_the_shutdown_dea ) locked, locked_total = build_while_store_locked(project_dir) + unlocked: subprocess.CompletedProcess[bytes] = run(project_dir, "build") + recorded_builds: list[list[object]] = recall_rows( + project_dir, "SELECT count(*) FROM invocations WHERE command = 'build'" + ) stderr: str = locked.stderr.decode(errors="replace") assert locked.returncode == test_case.expected_exit_code assert test_case.expected_notice in stderr + assert [ + (int(dropped) > 0, int(failed)) for dropped, failed in INCOMPLETE_HISTORY.findall(stderr) + ] == [(True, test_case.expected_failed_records)], stderr + assert (unlocked.returncode, recorded_builds) == (0, [[test_case.expected_recorded_builds]]) assert stderr.rstrip().endswith("completed successfully; only its Recall history is affected.") assert locked_total < test_case.hang_guard_seconds, stderr