mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 06:29:20 +08:00
feat: 发布页前端工具改为等待浏览器回执后再继续模型
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""前端工具回执门闩:代次隔离、超时与迟到提交。"""
|
||||
|
||||
import asyncio
|
||||
|
||||
from application.client_tool_gate import (
|
||||
ClientToolGate,
|
||||
format_client_tool_result,
|
||||
)
|
||||
|
||||
|
||||
def test_format_failure_prefix():
|
||||
assert format_client_tool_result(True, "已写入标题") == "已写入标题"
|
||||
assert format_client_tool_result(False, "标题为空").startswith("写入失败")
|
||||
|
||||
|
||||
def test_submit_wakes_current_epoch_only():
|
||||
gate = ClientToolGate(timeout_seconds=1)
|
||||
|
||||
async def scenario():
|
||||
epoch = gate.begin("t1")
|
||||
gate.arm("t1", epoch, "call-1")
|
||||
late = gate.begin("t1")
|
||||
assert late != epoch
|
||||
assert gate.submit("t1", "call-1", True, "旧轮") is False
|
||||
gate.arm("t1", late, "call-2")
|
||||
assert gate.submit("t1", "call-2", True, "已写入标题") is True
|
||||
ok, message = await gate.wait("t1", late, "call-2")
|
||||
assert ok is True
|
||||
assert message == "已写入标题"
|
||||
assert gate.submit("t1", "call-2", True, "再次") is False
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_timeout_when_no_submit():
|
||||
gate = ClientToolGate(timeout_seconds=0.05)
|
||||
|
||||
async def scenario():
|
||||
epoch = gate.begin("t2")
|
||||
gate.arm("t2", epoch, "call")
|
||||
ok, message = await gate.wait("t2", epoch, "call")
|
||||
assert ok is False
|
||||
assert message == "前端未回执"
|
||||
|
||||
asyncio.run(scenario())
|
||||
Reference in New Issue
Block a user