fix(gateway): tolerate cancelled channel tasks during shutdown

This commit is contained in:
Xubin Ren
2026-06-22 23:20:45 +08:00
parent f80a78d5a8
commit e624943bac
4 changed files with 66 additions and 0 deletions
+37
View File
@@ -1222,6 +1222,43 @@ async def test_stop_all_handles_channel_exception():
assert mgr._dispatch_task is None
@pytest.mark.asyncio
async def test_stop_all_handles_channel_stop_cancelled_task():
"""stop_all should treat a channel's already-cancelled internals as stopped."""
class _StopCancelledChannel(BaseChannel):
name = "stopcancelled"
display_name = "Stop Cancelled"
async def start(self) -> None:
pass
async def stop(self) -> None:
raise asyncio.CancelledError("server task cancelled")
async def send(self, msg: OutboundMessage) -> None:
pass
fake_config = SimpleNamespace(
channels=ChannelsConfig(),
providers=SimpleNamespace(groq=SimpleNamespace(api_key="")),
)
mgr = ChannelManager.__new__(ChannelManager)
mgr.config = fake_config
mgr.bus = MessageBus()
next_channel = _StartableChannel(fake_config, mgr.bus)
mgr.channels = {
"stopcancelled": _StopCancelledChannel(fake_config, mgr.bus),
"next": next_channel,
}
mgr._dispatch_task = None
await mgr.stop_all()
assert next_channel.stopped is True
@pytest.mark.asyncio
async def test_start_all_no_channels_logs_warning():
"""start_all should log warning when no channels are enabled."""