feat(douyu): 整合自动化中心并修复重登队列
This commit is contained in:
@@ -22,6 +22,7 @@ from datetime import UTC, datetime, timedelta
|
||||
from tests.support.db import get_test_engine, make_test_session
|
||||
from web.backend.models import (
|
||||
Account,
|
||||
AccountWorkItem,
|
||||
AutomationJob,
|
||||
LoginAttempt,
|
||||
LoginQuotaSetting,
|
||||
@@ -735,6 +736,43 @@ class TestSettlementVisibility(_Base):
|
||||
checker.close()
|
||||
stale.close()
|
||||
|
||||
def test_settlement_releases_claimed_account_without_attempt(self):
|
||||
"""预算跳过等无尝试记录场景也必须结束 running 工作项。"""
|
||||
account = self.make_account("acc-no-attempt")
|
||||
now = datetime.now(UTC)
|
||||
work = AccountWorkItem(
|
||||
account_id=account.id,
|
||||
work_type=ck_relogin.WORK_LOGIN_RELOGIN,
|
||||
priority=30,
|
||||
status="running",
|
||||
due_at=now,
|
||||
attempt_count=1,
|
||||
max_attempts=20,
|
||||
dedupe_key=f"login_relogin:{account.id}",
|
||||
started_at=now,
|
||||
)
|
||||
self.session.add(work)
|
||||
self.session.commit()
|
||||
|
||||
counters = ck_relogin.settle_fresh_results(
|
||||
"batch-without-attempts",
|
||||
now=now,
|
||||
max_attempts=2,
|
||||
expected_account_ids=[account.id],
|
||||
)
|
||||
|
||||
checker = make_test_session(self.engine)
|
||||
try:
|
||||
settled_work = checker.get(AccountWorkItem, work.id)
|
||||
settled_account = checker.get(Account, account.id)
|
||||
assert counters["scanned"] == 1
|
||||
assert counters["retry"] == 1
|
||||
assert settled_work.status == "pending"
|
||||
assert settled_work.due_at >= now + timedelta(minutes=59)
|
||||
assert settled_account.relogin_next_at >= now + timedelta(minutes=59)
|
||||
finally:
|
||||
checker.close()
|
||||
|
||||
def test_settlement_marks_real_success_as_valid(self):
|
||||
"""结算看到 success 就必须清零退避,不能写成失败。"""
|
||||
account = self.make_account(
|
||||
|
||||
Reference in New Issue
Block a user