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
21 changes: 21 additions & 0 deletions tests/integration/test_cell_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
waiting_since = time.monotonic()
await sleeping.wait()
budget.end += time.monotonic() - waiting_since
return await asyncio.wait(tasks, **options)

if ending == "deadline":
# Keep fixture setup time outside the deadline under test.
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),
Expand All @@ -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":
Expand Down
Loading