Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions tests/integration/test_cell_prepared_bot_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,19 +187,48 @@ 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 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()
return body.get("readiness", {}).get("ready") is True
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(
"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"
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
Expand Down
Loading