perf(automation): 持久队列驱动并优化履约热路径

This commit is contained in:
yml
2026-11-23 15:07:31 +08:00
parent 11c2a0dba7
commit 2549511598
31 changed files with 1658 additions and 235 deletions
+94
View File
@@ -0,0 +1,94 @@
"""独立后台进程生命周期测试。"""
from __future__ import annotations
from web.backend import background_runtime
def test_background_services_start_and_stop_once(monkeypatch):
calls: list[str] = []
def mark(name: str):
return lambda *_args, **_kwargs: calls.append(name) or True
monkeypatch.setattr(
"web.backend.services.automation.register_default_jobs",
mark("register"),
)
monkeypatch.setattr(
"web.backend.services.automation.start_scheduler",
mark("scheduler"),
)
monkeypatch.setattr(
"web.backend.services.automation.stop_scheduler",
mark("stop-scheduler"),
)
monkeypatch.setattr(
"web.backend.services.platform_fulfillment.reconciler."
"start_platform_fulfillment_reconciler",
mark("reconciler"),
)
monkeypatch.setattr(
"web.backend.services.platform_fulfillment.reconciler."
"stop_platform_fulfillment_reconciler",
mark("stop-reconciler"),
)
monkeypatch.setattr(
"web.backend.services.platform_fulfillment.auto_allocator."
"start_platform_fulfillment_auto_allocator",
mark("allocator"),
)
monkeypatch.setattr(
"web.backend.services.platform_fulfillment.auto_allocator."
"stop_platform_fulfillment_auto_allocator",
mark("stop-allocator"),
)
monkeypatch.setattr(
"web.backend.services.binding_poll_scheduler."
"start_binding_poll_scheduler",
mark("binding"),
)
monkeypatch.setattr(
"web.backend.services.binding_poll_scheduler."
"stop_binding_poll_scheduler",
mark("stop-binding"),
)
monkeypatch.setattr(
"web.backend.services.payment_poll_scheduler."
"start_payment_poll_scheduler",
mark("payment"),
)
monkeypatch.setattr(
"web.backend.services.payment_poll_scheduler."
"stop_payment_poll_scheduler",
mark("stop-payment"),
)
monkeypatch.setattr(
"web.backend.services.integration.start_integration_outbox_worker",
mark("outbox"),
)
monkeypatch.setattr(
"web.backend.services.integration.stop_integration_outbox_worker",
mark("stop-outbox"),
)
assert background_runtime.start_background_services() is True
assert background_runtime.start_background_services() is False
background_runtime.stop_background_services()
background_runtime.stop_background_services()
assert calls == [
"register",
"scheduler",
"outbox",
"reconciler",
"allocator",
"binding",
"payment",
"stop-payment",
"stop-binding",
"stop-allocator",
"stop-reconciler",
"stop-outbox",
"stop-scheduler",
]