feat(очередь): место получено — «начинаю работу» сразу; закрытие в этот миг не уносит место; версия 2026-10-28b
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,12 @@ def test_waiting_run_is_told_about_queue_and_kept_alive(bridge):
|
||||
assert sum(c == ": keepalive\n\n" for c in waiting) >= 3 # тишины нет, пока ждёт
|
||||
assert not any("ответ b" in c for c in waiting) # пока ждёт — не работает
|
||||
assert any("ответ b" in c for c in out_b) # место освободилось — доработал
|
||||
# место получено — строка «вы в очереди» сменяется сразу, а не с первым словом агента
|
||||
marks = [json.loads(c.split("data: ", 1)[1])["position"] for c in out_b
|
||||
if c.startswith("event: queue")]
|
||||
assert marks == [1, 0]
|
||||
first_answer = next(i for i, c in enumerate(out_b) if "ответ b" in c)
|
||||
assert out_b.index(next(c for c in out_b if '"position": 0' in c)) < first_answer
|
||||
|
||||
|
||||
def test_abandoned_wait_does_not_take_the_slot(bridge):
|
||||
@@ -124,3 +130,31 @@ def test_zero_keepalive_setting_falls_back(monkeypatch):
|
||||
monkeypatch.setenv("AGENT_QUEUE_KEEPALIVE", bad)
|
||||
importlib.reload(claude_bridge)
|
||||
assert claude_bridge.QUEUE_KEEPALIVE == 20.0
|
||||
|
||||
|
||||
def test_closing_right_after_slot_given_frees_it(bridge):
|
||||
cb, gates = bridge
|
||||
|
||||
async def scenario():
|
||||
for u in ("a", "b", "c"):
|
||||
gates[u] = asyncio.Event()
|
||||
gates["c"].set()
|
||||
ta = asyncio.create_task(_drain(cb, "a", []))
|
||||
await asyncio.sleep(0.02)
|
||||
gen = cb.stream_claude("привет", "b", "tab")
|
||||
|
||||
async def read_until_slot():
|
||||
async for chunk in gen:
|
||||
if '"position": 0' in chunk:
|
||||
return # человек ушёл ровно тут
|
||||
tb = asyncio.create_task(read_until_slot())
|
||||
await asyncio.sleep(0.1)
|
||||
gates["a"].set()
|
||||
await asyncio.wait_for(asyncio.gather(ta, tb), 5)
|
||||
await gen.aclose()
|
||||
out_c = []
|
||||
await asyncio.wait_for(_drain(cb, "c", out_c), 2)
|
||||
return out_c
|
||||
|
||||
out_c = asyncio.run(scenario())
|
||||
assert not any("event: queue" in c for c in out_c)
|
||||
|
||||
Reference in New Issue
Block a user