From dc5ee6755b839a5b15eaaadfc2b43b340a527b4c Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Sat, 4 Apr 2026 21:41:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E7=A7=BB=E9=99=A4=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=B5=9B=E9=A9=AC=E6=A8=A1=E6=8B=9F=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E9=94=81=E6=9C=BA=E5=88=B6=E4=BB=A5=E9=81=BF=E5=85=8D=E6=AD=BB?= =?UTF-8?q?=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构测试模拟赛马流程,移除房间锁获取逻辑,改为直接清理现有房间状态。 引入沙盒环境构建提示信息,提升测试过程的可观测性。 --- .../plugins/group_horse_racing/test_commands.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/danding_bot/plugins/group_horse_racing/test_commands.py b/danding_bot/plugins/group_horse_racing/test_commands.py index 56cba00..dea227a 100644 --- a/danding_bot/plugins/group_horse_racing/test_commands.py +++ b/danding_bot/plugins/group_horse_racing/test_commands.py @@ -205,24 +205,17 @@ async def handle_test_simulate_race(bot: Bot, event: Event): await test_simulate_race_cmd.send("收到:测试模拟赛马,开始执行完全模拟(无真实积分/数据库副作用)") scope = get_scope(event) - lock = room_store.get_lock(scope) - try: - await asyncio.wait_for(lock.acquire(), timeout=3) - except TimeoutError: - await test_simulate_race_cmd.finish("完全模拟失败:房间锁被占用(可能有卡住的赛马/测试任务),请稍后重试或先重启 Bot") - return - try: race_engine.stop_race(scope) room_store.delete_room(scope) - finally: - lock.release() - + except Exception: + pass original_room_store = commands_mod.room_store original_points_service = commands_mod.points_service original_message_service = commands_mod.message_service original_tick_interval = commands_mod.config.RACE_TICK_INTERVAL + fake_room_store = _InMemoryRoomStore() fake_points_service = _InMemoryPointsService() fake_message_service = _NoopMessageService() @@ -232,6 +225,7 @@ async def handle_test_simulate_race(bot: Bot, event: Event): room = None try: + await test_simulate_race_cmd.send("阶段:构建沙盒环境与参赛数据") commands_mod.room_store = fake_room_store commands_mod.points_service = fake_points_service commands_mod.message_service = fake_message_service @@ -252,6 +246,7 @@ async def handle_test_simulate_race(bot: Bot, event: Event): for horse in room.horses.values(): horse.state = HorseState.RACING + await test_simulate_race_cmd.send("阶段:执行赛程(后台任务)") start_task = asyncio.create_task(commands_mod.run_race_with_settlement(fake_bot, room, scope)) commands_mod.race_engine.register_task(scope, start_task) await asyncio.wait_for(start_task, timeout=15)