test(gateway): align runtime-tasks gather tests with bounded retrieval

The helper never waits on the runtime-tasks gather after cancelling it
(its children are bounded individually), so the finished-gather test must
hand the helper an already-complete gather to exercise the bounded
retrieval path, and the cancelled-gather test must settle the gather
itself instead of expecting the helper to await a still-pending future.

Use a pre-completed child for the finished case and suppress(await) for
the cancelled case; both now assert done() and a single close.
This commit is contained in:
arcdrake22 2026-08-03 09:13:36 +02:00 committed by Xubin Ren
parent 39e1533c3b
commit c6bd5f0075

View File

@ -9,6 +9,7 @@ block the stop.
import asyncio
import time
from contextlib import suppress
from nanobot.cli.gateway_runtime import _close_gateway_runtime
@ -160,7 +161,10 @@ async def test_duplicate_cleanup_is_idempotent() -> None:
async def test_finished_runtime_tasks_gather_is_retrieved() -> None:
agent = _FakeAgent()
channels = _FakeChannels()
runtime_tasks = asyncio.gather(asyncio.sleep(0))
finished = asyncio.get_running_loop().create_future()
finished.set_result(None)
runtime_tasks = asyncio.gather(finished)
await asyncio.sleep(0) # let the gather observe the finished child
await _close_gateway_runtime(agent, channels, [], runtime_tasks)
@ -175,6 +179,8 @@ async def test_cancelled_runtime_tasks_gather_does_not_raise() -> None:
runtime_tasks.cancel()
await _close_gateway_runtime(agent, channels, [], runtime_tasks)
with suppress(asyncio.CancelledError):
await runtime_tasks # settle the cancelled gather without raising
assert runtime_tasks.done() # the cancelled gather was awaited without raising
assert agent.close_calls == 1