更新
This commit is contained in:
@@ -213,6 +213,55 @@ class BatchStartApiTests(unittest.IsolatedAsyncioTestCase):
|
||||
)
|
||||
self.assertEqual(result["status"], "running")
|
||||
|
||||
async def test_batch_start_holds_no_db_connection_while_it_waits(self):
|
||||
"""A queued start must not pin one of the few pooled connections.
|
||||
|
||||
Credential validation and readiness waiting take seconds per account.
|
||||
Holding a session open across them exhausted the pool during a bulk
|
||||
start, so every unrelated request waited out ``pool_timeout``.
|
||||
"""
|
||||
account = SimpleNamespace(
|
||||
id=505,
|
||||
status="starting",
|
||||
qr_code_base64=None,
|
||||
error_message=None,
|
||||
im_session_data="saved-session",
|
||||
)
|
||||
events: list[str] = []
|
||||
assessment = {
|
||||
"login_mode": "im_direct",
|
||||
"should_reset": False,
|
||||
"can_skip_browser": True,
|
||||
"message": "ready",
|
||||
"cookie_valid": True,
|
||||
"im_ready": True,
|
||||
}
|
||||
|
||||
async def commit():
|
||||
events.append("release")
|
||||
|
||||
async def assess(*_args, **_kwargs):
|
||||
events.append("assess")
|
||||
return assessment
|
||||
|
||||
async def start_worker(*_args, **_kwargs):
|
||||
events.append("start-worker")
|
||||
return True
|
||||
|
||||
db = SimpleNamespace(commit=AsyncMock(side_effect=commit))
|
||||
|
||||
with (
|
||||
patch.object(main.manager, "is_running", return_value=False),
|
||||
patch.object(main.manager, "start_worker", AsyncMock(side_effect=start_worker)),
|
||||
patch.object(main, "_get_account_cookie_data", return_value="{}"),
|
||||
patch.object(main, "assess_account_credential", AsyncMock(side_effect=assess)),
|
||||
):
|
||||
await main._start_account_rpa_impl(account, db, wait_for_ready=True)
|
||||
|
||||
# "starting" was already persisted, so the only commits here exist to
|
||||
# return the connection: one before validation, one before the wait.
|
||||
self.assertEqual(events, ["release", "assess", "release", "start-worker"])
|
||||
|
||||
async def test_batch_start_does_not_launch_interactive_browser_login(self):
|
||||
account = SimpleNamespace(
|
||||
id=504,
|
||||
|
||||
Reference in New Issue
Block a user