Skip to content

Commit 57e87ee

Browse files
committed
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.
1 parent fce05cd commit 57e87ee

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎tests/e2e/src/sqlbuild/cli/commands/main/clickhouse/test_clickhouse_recall_views.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,13 @@ def test_given_one_invocation_lookup_when_planned_then_each_table_is_read_once_b
377377
assert run(project_dir, "build").returncode == 0
378378
# A command that ends before its first heartbeat writes none, and ClickHouse plans a table
379379
# with no parts as a read of nothing, so give the heartbeats table a part before planning.
380+
# The row starts now: an expired TTL would drop it on insert and its empty part soon after.
380381
execute_clickhouse_sql(
381382
config=clickhouse_e2e_config,
382383
statements=(
383-
f"INSERT INTO {recall_database}.recall_heartbeats (invocation_id) "
384-
"VALUES ('planning-setup')",
384+
f"INSERT INTO {recall_database}.recall_heartbeats "
385+
"(invocation_id, invocation_started_at, beat_at, stale_at) "
386+
"VALUES ('planning-setup', now64(6), now64(6), now64(6))",
385387
),
386388
)
387389
sql: str = (

‎tests/integration/src/sqlbuild/cli/recall/_test_types.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class HeldLockTestCase:
101101
builds_before_lock: int
102102
expected_exit_code: int
103103
expected_notice: str
104+
expected_failed_records: int
105+
expected_recorded_builds: int
104106
#: Far beyond the budget; only a build that waits for the lock itself reaches it.
105107
hang_guard_seconds: float
106108

‎tests/integration/src/sqlbuild/cli/recall/helpers.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
STOP_HANG_SECONDS: int = 120
3131
EMPTY_RESULT: bytes = b'{"rows": []}'
3232
NUMBERED_LINE: re.Pattern[bytes] = re.compile(rb"^(\d+) std(?:out|err)$", re.MULTILINE)
33+
INCOMPLETE_HISTORY: re.Pattern[str] = re.compile(r"incomplete \((\d+) dropped, (\d+) failed\)")
3334
PROJECT_TOML: str = (
3435
'name = "orders_shop"\n'
3536
'adapter = "duckdb"\n'

‎tests/integration/src/sqlbuild/cli/recall/test_local_recall.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
EMITTED_STDERR,
3434
EMITTED_STDOUT,
3535
EMITTED_TAIL,
36+
INCOMPLETE_HISTORY,
3637
MEBIBYTE,
3738
build_while_store_locked,
3839
build_with_failing_recall_notices,
@@ -546,6 +547,8 @@ def test_given_a_successful_command_when_recorded_then_it_ends_completed(
546547
builds_before_lock=1,
547548
expected_exit_code=0,
548549
expected_notice="Recall delivery did not finish within the shutdown timeout",
550+
expected_failed_records=0,
551+
expected_recorded_builds=2,
549552
hang_guard_seconds=60.0,
550553
),
551554
HeldLockTestCase(
@@ -554,6 +557,8 @@ def test_given_a_successful_command_when_recorded_then_it_ends_completed(
554557
builds_before_lock=0,
555558
expected_exit_code=0,
556559
expected_notice="Recall delivery did not finish within the shutdown timeout",
560+
expected_failed_records=0,
561+
expected_recorded_builds=1,
557562
hang_guard_seconds=60.0,
558563
),
559564
],
@@ -568,10 +573,18 @@ def test_given_a_locked_store_when_building_then_it_gives_up_at_the_shutdown_dea
568573
)
569574

570575
locked, locked_total = build_while_store_locked(project_dir)
576+
unlocked: subprocess.CompletedProcess[bytes] = run(project_dir, "build")
577+
recorded_builds: list[list[object]] = recall_rows(
578+
project_dir, "SELECT count(*) FROM invocations WHERE command = 'build'"
579+
)
571580

572581
stderr: str = locked.stderr.decode(errors="replace")
573582
assert locked.returncode == test_case.expected_exit_code
574583
assert test_case.expected_notice in stderr
584+
assert [
585+
(int(dropped) > 0, int(failed)) for dropped, failed in INCOMPLETE_HISTORY.findall(stderr)
586+
] == [(True, test_case.expected_failed_records)], stderr
587+
assert (unlocked.returncode, recorded_builds) == (0, [[test_case.expected_recorded_builds]])
575588
assert stderr.rstrip().endswith("completed successfully; only its Recall history is affected.")
576589
assert locked_total < test_case.hang_guard_seconds, stderr
577590

0 commit comments

Comments
 (0)