Skip to content

Commit ed1b0a7

Browse files
committed
test: 更新测试以避免 CI 随机失败
1 parent 5331cc8 commit ed1b0a7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tests/fake_adapter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Generic
44
from typing_extensions import override
55

6-
import anyio
6+
from anyio.lowlevel import checkpoint
77

88
from alicebot import Adapter, Event, MessageEvent
99
from alicebot.plugin import Plugin
@@ -15,6 +15,12 @@
1515
]
1616

1717

18+
async def allow_schedule_other_tasks() -> None:
19+
"""让出当前任务,允许其他任务执行。"""
20+
for _ in range(1000):
21+
await checkpoint()
22+
23+
1824
class FakeAdapter(Adapter[AnyEvent, None]):
1925
"""用于测试的适配器。"""
2026

@@ -37,10 +43,10 @@ async def run(self) -> None:
3743
await self.handle_event(event, handle_get=self.handle_get)
3844

3945
# 发送一个事件后,等待完成必要的处理再发送下一个
40-
await anyio.sleep(0.01)
46+
await allow_schedule_other_tasks()
4147

4248
# 尽可能让其他任务执行完毕后再退出
43-
await anyio.sleep(0.01)
49+
await allow_schedule_other_tasks()
4450

4551
self.bot.exit()
4652

0 commit comments

Comments
 (0)