fix(worker): 优化连接池容量拆分、并发入队与事件写入
This commit is contained in:
@@ -614,3 +614,60 @@ def test_default_enabled_job_is_created_enabled(db, monkeypatch):
|
||||
.one()
|
||||
)
|
||||
assert row.enabled is True
|
||||
|
||||
|
||||
def test_multi_commodity_refresh_handles_missing_and_due_states(db):
|
||||
from web.backend.services.platform_fulfillment.account_selector import (
|
||||
capability_refresh_candidate_accounts,
|
||||
)
|
||||
|
||||
missing_one = _account(db, "cap-multi-missing-one")
|
||||
fresh_storehome_missing = _account(db, "cap-multi-fresh-sh")
|
||||
due_one = _account(db, "cap-multi-due-one")
|
||||
all_fresh = _account(db, "cap-multi-all-fresh")
|
||||
|
||||
# missing_one 只有 C1 新鲜,缺少 C2,且 storehome 过期 -> 应被选中
|
||||
_state(db, missing_one, commodity_id="C1", valid_until=NOW + timedelta(hours=1))
|
||||
# fresh_storehome_missing 只有 C1 新鲜,缺少 C2,但 storehome 新鲜 -> 不应重复补扫
|
||||
_state(
|
||||
db,
|
||||
fresh_storehome_missing,
|
||||
commodity_id="C1",
|
||||
valid_until=NOW + timedelta(hours=1),
|
||||
)
|
||||
db.add(
|
||||
AccountSyncState(
|
||||
account_id=fresh_storehome_missing.id,
|
||||
platform="douyu",
|
||||
domain="storehome",
|
||||
status="success",
|
||||
last_success_at=NOW,
|
||||
valid_until=NOW + timedelta(hours=1),
|
||||
)
|
||||
)
|
||||
# due_one 两个都有,但 C2 已过期 -> 即使 storehome 新鲜也应被选中
|
||||
_state(db, due_one, commodity_id="C1", valid_until=NOW + timedelta(hours=1))
|
||||
_state(db, due_one, commodity_id="C2", valid_until=NOW - timedelta(minutes=1))
|
||||
db.add(
|
||||
AccountSyncState(
|
||||
account_id=due_one.id,
|
||||
platform="douyu",
|
||||
domain="storehome",
|
||||
status="success",
|
||||
last_success_at=NOW,
|
||||
valid_until=NOW + timedelta(hours=1),
|
||||
)
|
||||
)
|
||||
# all_fresh 两个都新鲜 -> 不应被选中
|
||||
_state(db, all_fresh, commodity_id="C1", valid_until=NOW + timedelta(hours=1))
|
||||
_state(db, all_fresh, commodity_id="C2", valid_until=NOW + timedelta(hours=1))
|
||||
db.commit()
|
||||
|
||||
selected = capability_refresh_candidate_accounts(
|
||||
db,
|
||||
commodity_ids=["C1", "C2"],
|
||||
scope="elite",
|
||||
limit=10,
|
||||
now=NOW,
|
||||
)
|
||||
assert {row.id for row in selected} == {missing_one.id, due_one.id}
|
||||
|
||||
Reference in New Issue
Block a user