From 843be9a5563b4a66ad7fa6ce5cb64cad3f0a7279 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Wed, 21 Oct 2026 17:17:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=89=A7=E8=A1=8C=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=8D=E4=BE=9D=E8=B5=96=E5=90=8C=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E9=87=8C=E7=9A=84=E6=95=B0=E6=8D=AE=E6=BA=90=E4=B8=AA?= =?UTF-8?q?=E6=95=B0=E3=80=81=E7=AD=89=E5=BE=85=E9=83=BD=E6=9C=89=E6=97=B6?= =?UTF-8?q?=E9=99=90=EF=BC=9A=E5=88=AB=E7=9A=84=E6=B5=8B=E8=AF=95=E5=BB=BA?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E6=BA=90=E8=B6=85=E8=BF=87=E8=AF=84?= =?UTF-8?q?=E6=B5=8B=E6=8B=8D=E7=9B=AE=E5=BD=95=E5=BF=AB=E7=85=A7=E7=9A=84?= =?UTF-8?q?=E4=B8=8A=E9=99=90=E6=97=B6=EF=BC=8C=E4=BD=9C=E7=AD=94=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E5=9C=A8=E6=8E=92=E9=98=9F=E5=89=8D=E5=B0=B1=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=EF=BC=8C=E5=8E=9F=E6=9D=A5=E7=9A=84=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E6=B0=B8=E8=BF=9C=E7=AD=89=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E3=80=81=E6=95=B4=E6=AC=A1=E6=B5=8B=E8=AF=95=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=EF=BC=88=E4=B8=8A=E4=BC=A0=E6=BA=90=E6=B5=8B=E8=AF=95=E5=92=8C?= =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=B5=8B=E8=AF=95=E5=88=86=E5=88=B0=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=BF=9B=E7=A8=8B=E6=97=B6=E5=A4=8D=E7=8E=B0?= =?UTF-8?q?=EF=BC=89=EF=BC=9B=E8=BF=99=E9=87=8C=E7=9A=84=E8=AF=84=E6=B5=8B?= =?UTF-8?q?=E4=B8=8D=E6=B5=8B=E8=BF=99=E4=B8=AA=E4=B8=8A=E9=99=90=EF=BC=8C?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=87=8C=E6=8A=8A=E4=B8=8A=E9=99=90=E6=94=BE?= =?UTF-8?q?=E5=A4=A7=EF=BC=8C=E7=AD=89=E5=BE=85=E6=94=B9=E6=88=90=2030=20?= =?UTF-8?q?=E7=A7=92=E7=AD=89=E4=B8=8D=E5=88=B0=E5=B0=B1=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=B9=B6=E8=AF=B4=E6=B8=85=E5=9C=A8=E7=AD=89=E4=BB=80=E4=B9=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/tests/test_eval_runner.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/tests/test_eval_runner.py b/backend/tests/test_eval_runner.py index 6aaaa484..c23e7b3c 100644 --- a/backend/tests/test_eval_runner.py +++ b/backend/tests/test_eval_runner.py @@ -33,7 +33,12 @@ async def _clear_ledger() -> None: @pytest.fixture(autouse=True) -async def engine_up(): +async def engine_up(monkeypatch): + # 同一个测试进程里别的测试建的数据源可能超过评测拍目录快照的上限(app/eval/snapshots.MAX_SOURCES),评测会按 + # 设计报「数据源超过 20 个」——这里的评测不测这个上限,分到哪个进程都要照常跑 + from app.eval import snapshots + + monkeypatch.setattr(snapshots, "MAX_SOURCES", 10_000) await run_manager.setup() await _clear_ledger() yield @@ -49,6 +54,16 @@ async def client(): yield c +async def _until(cond, what: str, *, timeout: float = 30.0) -> None: + """等到 cond() 为真;等不到就让测试失败、说清在等什么,不让整次测试卡死(作答运行在排队之前就失败时,排队永远等不到)。""" + loop = asyncio.get_running_loop() + deadline = loop.time() + timeout + while not await cond(): + if loop.time() > deadline: + raise AssertionError(f"等了 {timeout:g} 秒还没等到:{what}") + await asyncio.sleep(0.02) + + def ask_cases(n: int) -> list[dict]: return [{"question": f"第 {i} 个含糊的问题", "expectations": [{"kind": "ask"}]} for i in range(1, n + 1)] @@ -327,12 +342,13 @@ async def test_time_queued_for_a_run_slot_does_not_count_against_the_case_limit( monkeypatch.setattr(runner.EvalExecution, "_prepare", prepare) held = asyncio.create_task(blocker()) try: - while not (await slots.snapshot())["classes"]["system"]["running"]: - await asyncio.sleep(0.02) + async def blocking() -> bool: + return bool((await slots.snapshot())["classes"]["system"]["running"]) + + await _until(blocking, "占名额的那一段拿到名额") suite_id = await es.make_suite("none", cases=ask_cases(1)) [run] = await start(suite_id) - while not await slots.waiting("eval-answer-in-queue"): - await asyncio.sleep(0.02) + await _until(lambda: slots.waiting("eval-answer-in-queue"), "作答运行排队等名额") await asyncio.sleep(2.0) gate.set() await es.wait_eval(run.id)