Merge pull request #1389 from NousResearch/hermes/hermes-7ef7cb6a
fix(telegram): check updater/app state before disconnect
This commit is contained in:
commit
69045711c1
2 changed files with 29 additions and 2 deletions
|
|
@ -275,8 +275,11 @@ class TelegramAdapter(BasePlatformAdapter):
|
||||||
|
|
||||||
if self._app:
|
if self._app:
|
||||||
try:
|
try:
|
||||||
await self._app.updater.stop()
|
# Only stop the updater if it's running
|
||||||
await self._app.stop()
|
if self._app.updater and self._app.updater.running:
|
||||||
|
await self._app.updater.stop()
|
||||||
|
if self._app.running:
|
||||||
|
await self._app.stop()
|
||||||
await self._app.shutdown()
|
await self._app.shutdown()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("[%s] Error during Telegram disconnect: %s", self.name, e, exc_info=True)
|
logger.warning("[%s] Error during Telegram disconnect: %s", self.name, e, exc_info=True)
|
||||||
|
|
|
||||||
|
|
@ -98,3 +98,27 @@ async def test_polling_conflict_stops_polling_and_notifies_handler(monkeypatch):
|
||||||
assert adapter.has_fatal_error is True
|
assert adapter.has_fatal_error is True
|
||||||
updater.stop.assert_awaited()
|
updater.stop.assert_awaited()
|
||||||
fatal_handler.assert_awaited_once()
|
fatal_handler.assert_awaited_once()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_disconnect_skips_inactive_updater_and_app(monkeypatch):
|
||||||
|
adapter = TelegramAdapter(PlatformConfig(enabled=True, token="***"))
|
||||||
|
|
||||||
|
updater = SimpleNamespace(running=False, stop=AsyncMock())
|
||||||
|
app = SimpleNamespace(
|
||||||
|
updater=updater,
|
||||||
|
running=False,
|
||||||
|
stop=AsyncMock(),
|
||||||
|
shutdown=AsyncMock(),
|
||||||
|
)
|
||||||
|
adapter._app = app
|
||||||
|
|
||||||
|
warning = MagicMock()
|
||||||
|
monkeypatch.setattr("gateway.platforms.telegram.logger.warning", warning)
|
||||||
|
|
||||||
|
await adapter.disconnect()
|
||||||
|
|
||||||
|
updater.stop.assert_not_awaited()
|
||||||
|
app.stop.assert_not_awaited()
|
||||||
|
app.shutdown.assert_awaited_once()
|
||||||
|
warning.assert_not_called()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue