From 7f1f2ba93cfcf5d9e8450f3a45723b7e7eb057d0 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 5 Dec 2026 04:13:21 +0530 Subject: [PATCH 1/2] The restore deadline test waits for the blocked query Opening a Postgres connection can consume the deadline before initialization starts. Arm the test deadline after observing the blocked query so the test measures cleanup of the owned backend. Signed-off-by: Lareb Zafar --- tests/integration/test_cell_restore.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/integration/test_cell_restore.py b/tests/integration/test_cell_restore.py index 922b664d2df..920e281c26e 100644 --- a/tests/integration/test_cell_restore.py +++ b/tests/integration/test_cell_restore.py @@ -346,6 +346,7 @@ async def test_restore_owns_raw_backend_before_initialization( import argparse import asyncio import time + from types import SimpleNamespace import asyncpg import httpx @@ -375,6 +376,25 @@ async def blocked(conn): monkeypatch.setattr(pg, "close_owned", public_close) seconds = 0.3 if ending == "deadline" else 1.0 budget = cell_restore.Budget(seconds) + sleeping = asyncio.Event() + first_wait = True + + async def wait_for_opening(tasks, **options): + nonlocal first_wait + if first_wait: + first_wait = False + await sleeping.wait() + budget.end = time.monotonic() + seconds + options["timeout"] = budget.left() + return await asyncio.wait(tasks, **options) + + if ending == "deadline": + # Start the deadline while the backend is blocked in initialization. + monkeypatch.setattr( + cell_restore, + "asyncio", + SimpleNamespace(create_task=asyncio.create_task, wait=wait_for_opening), + ) task = asyncio.create_task( cell_restore.Restore( argparse.Namespace(cell="first", wait=seconds), @@ -394,6 +414,7 @@ async def blocked(conn): else: pytest.fail("raw initialization never reached its actual sleeping query") before = time.monotonic() + sleeping.set() if ending != "deadline": task.cancel("first initialization cancellation") if ending == "second_cancel": From 4ce374cd4453298c63d7fab40ef628dc48aa1e92 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 5 Dec 2026 04:17:46 +0530 Subject: [PATCH 2/2] The restore test uses the production wait timeout Extend the test budget by the time spent waiting for the observer. The first wait still uses the timeout computed by the restore budget. Signed-off-by: Lareb Zafar --- tests/integration/test_cell_restore.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_cell_restore.py b/tests/integration/test_cell_restore.py index 920e281c26e..1b6ccf3f5e7 100644 --- a/tests/integration/test_cell_restore.py +++ b/tests/integration/test_cell_restore.py @@ -383,13 +383,13 @@ async def wait_for_opening(tasks, **options): nonlocal first_wait if first_wait: first_wait = False + waiting_since = time.monotonic() await sleeping.wait() - budget.end = time.monotonic() + seconds - options["timeout"] = budget.left() + budget.end += time.monotonic() - waiting_since return await asyncio.wait(tasks, **options) if ending == "deadline": - # Start the deadline while the backend is blocked in initialization. + # Keep fixture setup time outside the deadline under test. monkeypatch.setattr( cell_restore, "asyncio",