From ebf2bc5badfb64ad6d931f5a9c682309dbf56d1d Mon Sep 17 00:00:00 2001 From: 1zzxy1 <1535960104@qq.com> Date: Wed, 25 Mar 2026 11:01:42 +0800 Subject: [PATCH 1/2] fix: keep weixin_oc polling after inbound timeouts --- .../sources/weixin_oc/weixin_oc_adapter.py | 8 +++- tests/test_weixin_oc_adapter.py | 48 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/test_weixin_oc_adapter.py diff --git a/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py b/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py index b9caa0b093..c47b58087e 100644 --- a/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py +++ b/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py @@ -895,7 +895,13 @@ async def run(self) -> None: await asyncio.sleep(self.qr_poll_interval) continue - await self._poll_inbound_updates() + try: + await self._poll_inbound_updates() + except asyncio.TimeoutError: + logger.debug( + "weixin_oc(%s): inbound long-poll timeout", + self.meta().id, + ) except asyncio.CancelledError: raise except Exception as e: diff --git a/tests/test_weixin_oc_adapter.py b/tests/test_weixin_oc_adapter.py new file mode 100644 index 0000000000..269aa60fe1 --- /dev/null +++ b/tests/test_weixin_oc_adapter.py @@ -0,0 +1,48 @@ +import asyncio +from unittest.mock import AsyncMock, patch + +import pytest + +from astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter import WeixinOCAdapter + + +def _make_adapter() -> WeixinOCAdapter: + return WeixinOCAdapter( + platform_config={ + "id": "weixin_main", + "type": "weixin_oc", + "weixin_oc_token": "test-token", + }, + platform_settings={}, + event_queue=asyncio.Queue(), + ) + + +@pytest.mark.asyncio +async def test_run_keeps_polling_after_inbound_timeout(): + adapter = _make_adapter() + adapter.client.close = AsyncMock() + + calls = 0 + + async def fake_poll_inbound_updates(): + nonlocal calls + calls += 1 + if calls == 1: + raise asyncio.TimeoutError() + adapter._shutdown_event.set() + + adapter._poll_inbound_updates = fake_poll_inbound_updates # type: ignore[method-assign] + + with patch( + "astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter.logger" + ) as mock_logger: + await adapter.run() + + assert calls == 2 + mock_logger.debug.assert_any_call( + "weixin_oc(%s): inbound long-poll timeout", + "weixin_main", + ) + mock_logger.exception.assert_not_called() + adapter.client.close.assert_awaited_once() From dd0b413c5edbc4755debccd36012ca07ce4ac99d Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Wed, 25 Mar 2026 16:19:55 +0800 Subject: [PATCH 2/2] Delete tests/test_weixin_oc_adapter.py --- tests/test_weixin_oc_adapter.py | 48 --------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 tests/test_weixin_oc_adapter.py diff --git a/tests/test_weixin_oc_adapter.py b/tests/test_weixin_oc_adapter.py deleted file mode 100644 index 269aa60fe1..0000000000 --- a/tests/test_weixin_oc_adapter.py +++ /dev/null @@ -1,48 +0,0 @@ -import asyncio -from unittest.mock import AsyncMock, patch - -import pytest - -from astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter import WeixinOCAdapter - - -def _make_adapter() -> WeixinOCAdapter: - return WeixinOCAdapter( - platform_config={ - "id": "weixin_main", - "type": "weixin_oc", - "weixin_oc_token": "test-token", - }, - platform_settings={}, - event_queue=asyncio.Queue(), - ) - - -@pytest.mark.asyncio -async def test_run_keeps_polling_after_inbound_timeout(): - adapter = _make_adapter() - adapter.client.close = AsyncMock() - - calls = 0 - - async def fake_poll_inbound_updates(): - nonlocal calls - calls += 1 - if calls == 1: - raise asyncio.TimeoutError() - adapter._shutdown_event.set() - - adapter._poll_inbound_updates = fake_poll_inbound_updates # type: ignore[method-assign] - - with patch( - "astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter.logger" - ) as mock_logger: - await adapter.run() - - assert calls == 2 - mock_logger.debug.assert_any_call( - "weixin_oc(%s): inbound long-poll timeout", - "weixin_main", - ) - mock_logger.exception.assert_not_called() - adapter.client.close.assert_awaited_once()