chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑
This commit is contained in:
1 parent
5ef8329bd8
commit
4ec4e57005
183 files changed
+14653
-3936
No files matched your search
@@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -60,3 +62,44 @@ def test_write_shared_mount_sentinel_writes_scope_file(tmp_path, monkeypatch):
|
||||
content = sentinel.read_text(encoding="utf-8")
|
||||
assert "scope_id=hxops-rpa-test-data" in content
|
||||
assert "host=WIN-RPA-01" in content
|
||||
|
||||
|
||||
def test_maybe_send_heartbeat_does_not_block_trigger_loop_when_http_stalls(tmp_path, monkeypatch):
|
||||
"""断言底层 HTTP 卡住时,主 Worker 仍能立即继续扫描 Trigger。"""
|
||||
module = _load_freight_rpa_heartbeat_module()
|
||||
release_request = threading.Event()
|
||||
request_started = threading.Event()
|
||||
calls: list[dict] = []
|
||||
|
||||
def stalled_post(payload):
|
||||
calls.append(payload)
|
||||
request_started.set()
|
||||
release_request.wait(timeout=2)
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(module, "post_heartbeat", stalled_post)
|
||||
monkeypatch.setenv("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_SECONDS", "15")
|
||||
started = time.monotonic()
|
||||
sent_at = module.maybe_send_heartbeat(
|
||||
trigger_dir=tmp_path,
|
||||
drop_dir=tmp_path,
|
||||
last_sent_mono=0.0,
|
||||
force=True,
|
||||
)
|
||||
|
||||
# 核心断言:投递而非等待卡住的 HTTP 请求,扫描循环可立即继续。
|
||||
assert time.monotonic() - started < 0.2
|
||||
assert sent_at > 0
|
||||
assert request_started.wait(timeout=0.5)
|
||||
|
||||
module.maybe_send_heartbeat(
|
||||
trigger_dir=tmp_path,
|
||||
drop_dir=tmp_path,
|
||||
last_sent_mono=0.0,
|
||||
force=True,
|
||||
)
|
||||
# 同一时刻只允许一个后台请求,避免后端异常时线程无限累积。
|
||||
assert len(calls) == 1
|
||||
release_request.set()
|
||||
assert module._HEARTBEAT_THREAD is not None
|
||||
module._HEARTBEAT_THREAD.join(timeout=1)
|
||||
Reference in new issue
Block a user