fix: 采集账号失败就换号,都不可用时任务留待再试
This commit is contained in:
@@ -216,6 +216,37 @@ def test_collection_borrows_the_less_used_account(client: TestClient):
|
||||
assert session.get(NqiAccount, account_id).active_tasks == 0
|
||||
|
||||
|
||||
def test_borrow_skips_an_account_that_just_failed(client: TestClient):
|
||||
from app.collect.accounts import borrow_account, release_account
|
||||
from app.db import session_scope
|
||||
from app.models import NqiAccount
|
||||
|
||||
with session_scope() as session:
|
||||
session.add(NqiAccount(login_id="first", credential_valid=True, cookies=[{"name": "a"}]))
|
||||
session.add(NqiAccount(login_id="second", credential_valid=True, cookies=[{"name": "b"}]))
|
||||
first_id, _cookies = borrow_account()
|
||||
release_account(first_id, invalid=True)
|
||||
second_id, cookies = borrow_account({first_id})
|
||||
assert cookies == [{"name": "b"}]
|
||||
with session_scope() as session:
|
||||
assert session.get(NqiAccount, first_id).credential_valid is False
|
||||
assert session.get(NqiAccount, second_id).login_id == "second"
|
||||
release_account(second_id)
|
||||
|
||||
|
||||
def test_auth_failure_switches_account():
|
||||
from app.collect.accounts import AccountUnavailable
|
||||
from app.nqi.client import NqiAuthError
|
||||
from app.tasks.runner import _use_account
|
||||
|
||||
def fail():
|
||||
raise NqiAuthError("登录已失效")
|
||||
|
||||
with pytest.raises(AccountUnavailable) as caught:
|
||||
_use_account(fail)
|
||||
assert caught.value.invalid is True
|
||||
|
||||
|
||||
def test_concurrency_bounds():
|
||||
assert check_concurrency(1) == 1
|
||||
assert check_concurrency(32) == 32
|
||||
|
||||
Reference in New Issue
Block a user