From 957a8a287c4744fa2be7822dac70652fd8966693 Mon Sep 17 00:00:00 2001 From: liuhao1024 Date: Tue, 15 Sep 2026 03:00:57 +0800 Subject: [PATCH] test(feishu): restore the loop default executor torn down by the dedup test The regression test swaps in a torn-down default executor but never restores the pristine one, leaking the poisoned executor to anything sharing the loop. Save/restore via the private slot because set_default_executor() rejects None, which is exactly the pristine (lazy-creation) state. Also apply ruff format to the file. --- tests/gateway/test_feishu_sdk_executor.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/gateway/test_feishu_sdk_executor.py b/tests/gateway/test_feishu_sdk_executor.py index 92126cdb76..3666ebefc0 100644 --- a/tests/gateway/test_feishu_sdk_executor.py +++ b/tests/gateway/test_feishu_sdk_executor.py @@ -8,6 +8,7 @@ ThreadPoolExecutor and recreates it on demand if it has been shut down. Covers: #10849, #111020 """ + import asyncio import concurrent.futures import json @@ -60,7 +61,9 @@ async def test_run_blocking_executes_on_owned_pool(): @pytest.mark.asyncio -async def test_is_duplicate_flush_survives_default_executor_teardown(tmp_path, monkeypatch): +async def test_is_duplicate_flush_survives_default_executor_teardown( + tmp_path, monkeypatch +): """The inbound dedup flush must not ride the loop's default executor. After the adapter's background event loop dies, its teardown shuts the @@ -73,8 +76,11 @@ async def test_is_duplicate_flush_survives_default_executor_teardown(tmp_path, m from gateway.config import PlatformConfig adapter = FeishuAdapter(PlatformConfig()) + loop = asyncio.get_running_loop() + # Save/restore via the private slot: set_default_executor() rejects None, but the + # pristine state is exactly "no default executor set yet" (lazy creation on first use). + original_executor = loop._default_executor try: - loop = asyncio.get_running_loop() torn_down = concurrent.futures.ThreadPoolExecutor(max_workers=1) loop.set_default_executor(torn_down) torn_down.shutdown(wait=True) @@ -85,9 +91,10 @@ async def test_is_duplicate_flush_survives_default_executor_teardown(tmp_path, m # The dedup gate must still admit the message and flush it to disk. assert await adapter._is_duplicate("om_after_executor_teardown") is False - state = json.loads((tmp_path / "feishu_seen_message_ids.json").read_text(encoding="utf-8")) + state = json.loads( + (tmp_path / "feishu_seen_message_ids.json").read_text(encoding="utf-8") + ) assert "om_after_executor_teardown" in state["message_ids"] finally: + loop._default_executor = original_executor adapter._shutdown_sdk_executor() - -