From a70bf1f2426a4d3d1fed3fd018812e38e0c17781 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Fri, 4 Dec 2026 00:37:18 +0530 Subject: [PATCH 1/3] Prepared bot tests wait for enforced tenancy General health permits recording mode while the bot identity check requires the serving process to have read enforced mode. Wait for that process to report the transition before provisioning. Signed-off-by: Lareb Zafar --- .../test_cell_prepared_bot_native.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_cell_prepared_bot_native.py b/tests/integration/test_cell_prepared_bot_native.py index 562b920703..2f664227e3 100644 --- a/tests/integration/test_cell_prepared_bot_native.py +++ b/tests/integration/test_cell_prepared_bot_native.py @@ -194,12 +194,31 @@ def ready(): if response.status_code != 200: return False body = response.json() - return body.get("readiness", {}).get("ready") is True + if body.get("readiness", {}).get("ready") is not True: + return False + # Health permits recording mode. Bot proof requires this web process to + # have read enforced mode from the store. + rows = ( + node["ch"] + .query( + "SELECT tenancy_mode FROM {db:Identifier}.cell_heartbeats " + "WHERE instance_id = {instance:String}", + parameters={ + "db": node["database"], + "instance": body["deployment_config"]["instance_id"], + }, + ) + .result_rows + ) + return bool(rows) and rows[0][0] == "enforced" remaining = end - time.monotonic() assert remaining > 0, "The original preparation budget expired" wait_until( - ready, max_wait=remaining, interval=0.2, description="prepared own-host readiness" + ready, + max_wait=remaining, + interval=0.2, + description="prepared own-host readiness in enforced mode", ) response = client.get(node["origin"] + "/v1/health/deployment") assert response.status_code == 200 From 68e71bb327016c9abcc2c41d16a04a9f74a6875e Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Fri, 4 Dec 2026 00:44:35 +0530 Subject: [PATCH 2/3] Bound the prepared cell heartbeat read Use a short-lived readiness client with bounded connect and read timeouts. Ignore a heartbeat that arrives after the preparation deadline. Signed-off-by: Lareb Zafar --- .../test_cell_prepared_bot_native.py | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/integration/test_cell_prepared_bot_native.py b/tests/integration/test_cell_prepared_bot_native.py index 2f664227e3..753fa31be6 100644 --- a/tests/integration/test_cell_prepared_bot_native.py +++ b/tests/integration/test_cell_prepared_bot_native.py @@ -13,7 +13,7 @@ import subprocess import sys import time -from contextlib import ExitStack, contextmanager +from contextlib import ExitStack, closing, contextmanager from dataclasses import dataclass from pathlib import Path from typing import Any @@ -187,30 +187,32 @@ def _prepare(node, router, operator, *, later): def _ready(node, certificate, end): context = ssl.create_default_context(cafile=str(certificate)) - with httpx.Client(verify=context, follow_redirects=False, trust_env=False, timeout=5) as client: + with ( + httpx.Client(verify=context, follow_redirects=False, trust_env=False, timeout=5) as client, + closing( + ch_client_from_env( + database=node["database"], + connect_timeout=2, + send_receive_timeout=2, + query_retries=0, + ) + ) as ch, + ): def ready(): response = client.get(node["origin"] + "/v1/health") if response.status_code != 200: return False body = response.json() - if body.get("readiness", {}).get("ready") is not True: + if body.get("readiness", {}).get("ready") is not True or time.monotonic() >= end: return False # Health permits recording mode. Bot proof requires this web process to # have read enforced mode from the store. - rows = ( - node["ch"] - .query( - "SELECT tenancy_mode FROM {db:Identifier}.cell_heartbeats " - "WHERE instance_id = {instance:String}", - parameters={ - "db": node["database"], - "instance": body["deployment_config"]["instance_id"], - }, - ) - .result_rows - ) - return bool(rows) and rows[0][0] == "enforced" + rows = ch.query( + "SELECT tenancy_mode FROM cell_heartbeats WHERE instance_id = {instance:String}", + parameters={"instance": body["deployment_config"]["instance_id"]}, + ).result_rows + return bool(rows) and rows[0][0] == "enforced" and time.monotonic() < end remaining = end - time.monotonic() assert remaining > 0, "The original preparation budget expired" From c2d72b1f2af34d5d2b84ebc79d4770a2ec6a0240 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Fri, 4 Dec 2026 00:55:03 +0530 Subject: [PATCH 3/3] Retry transient ClickHouse startup in the prepared-bot proof Open the heartbeat client within the existing readiness poll. Signed-off-by: Lareb Zafar --- .../test_cell_prepared_bot_native.py | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tests/integration/test_cell_prepared_bot_native.py b/tests/integration/test_cell_prepared_bot_native.py index 753fa31be6..2a60e24108 100644 --- a/tests/integration/test_cell_prepared_bot_native.py +++ b/tests/integration/test_cell_prepared_bot_native.py @@ -187,25 +187,33 @@ def _prepare(node, router, operator, *, later): def _ready(node, certificate, end): context = ssl.create_default_context(cafile=str(certificate)) - with ( - httpx.Client(verify=context, follow_redirects=False, trust_env=False, timeout=5) as client, - closing( - ch_client_from_env( - database=node["database"], - connect_timeout=2, - send_receive_timeout=2, - query_retries=0, - ) - ) as ch, - ): + with ExitStack() as stack: + client = stack.enter_context( + httpx.Client(verify=context, follow_redirects=False, trust_env=False, timeout=5) + ) + ch = None def ready(): + nonlocal ch response = client.get(node["origin"] + "/v1/health") if response.status_code != 200: return False body = response.json() if body.get("readiness", {}).get("ready") is not True or time.monotonic() >= end: return False + if ch is None: + ch = stack.enter_context( + closing( + ch_client_from_env( + database=node["database"], + connect_timeout=2, + send_receive_timeout=2, + query_retries=0, + ) + ) + ) + if time.monotonic() >= end: + return False # Health permits recording mode. Bot proof requires this web process to # have read enforced mode from the store. rows = ch.query(