54916aff86
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 5s
CI/CD Pipeline / Check push changed paths (push) Successful in 8s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 29s
CI/CD Pipeline / Build Staging API Image (push) Successful in 31s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 37s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 2m1s
CI/CD Pipeline / Integration Tests (push) Successful in 2m22s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m11s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m16s
CI/CD Pipeline / Validate - Style (push) Successful in 2m58s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m41s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 1m30s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 1m36s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 5m47s
CI/CD Pipeline / Validate - Security (push) Successful in 6m2s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m33s
AI Code Review / AI Code Review (pull_request) Successful in 6m27s
CI/CD Pipeline / Unit Tests (push) Successful in 8m30s
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 31s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 32s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 38s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 241h24m45s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 241h24m46s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 241h24m56s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 241h25m4s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 241h25m7s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 241h25m17s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 241h25m19s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 241h25m57s
CI/CD Pipeline / Canary Release to Production (push) Failing after 241h34m12s
CI/CD Pipeline / CI Gate (push) Failing after 241h34m16s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 241h34m16s
CI/CD Pipeline / Build Production API Image (push) Failing after 241h34m16s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 241h38m54s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 0s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 241h41m44s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 241h41m46s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 0s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 0s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 241h25m51s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 241h25m52s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 241h25m52s
CI/CD Pipeline / Validate - Security (pull_request) Failing after 241h25m56s
CI/CD Pipeline / Validate - Style (pull_request) Failing after 241h25m56s
CI/CD Pipeline / Frontend Lint (push) Failing after 241h42m46s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 241h42m51s
CI/CD Pipeline / PR Build API Image (push) Failing after 241h42m52s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 241h42m57s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 241h59m22s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 241h59m42s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 241h59m53s
CI/CD Pipeline / Deploy Production (push) Failing after 242h8m49s
CI/CD Pipeline / Build Production Web Image (push) Failing after 242h8m52s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 0s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Failing after 242h16m21s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 0s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 242h0m28s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 242h0m28s
CI/CD Pipeline / PR Build Web Image (push) Failing after 242h17m27s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
76 lines
2.8 KiB
Python
76 lines
2.8 KiB
Python
"""#1714 beat 任务 scheduled_cleanup_stale_ingest_jobs 薄封装测试。
|
||
|
||
mock SessionLocal 和清理核心,验证 beat 任务正确串联
|
||
cleanup_stale_ingest_jobs → cleanup_orphan_processing_assets → revoke 消息。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import sys
|
||
from pathlib import Path
|
||
from unittest.mock import MagicMock, patch
|
||
|
||
os.environ.setdefault("JWT_SECRET_KEY", "unit-test-secret")
|
||
os.environ.setdefault("DATABASE_URL", "sqlite:///test_beat.db")
|
||
|
||
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "worker"))
|
||
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "api"))
|
||
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||
|
||
import worker_app.tasks.cleanup as cleanup # noqa: E402
|
||
|
||
|
||
def test_beat_cleanup_calls_core_and_revokes():
|
||
"""beat 任务串联三个核心步骤,返回汇总计数。"""
|
||
fake_session = MagicMock()
|
||
|
||
with (
|
||
patch("worker_app.db.SessionLocal", return_value=fake_session) as m_db,
|
||
patch(
|
||
"packages.application.ingest_orphan_cleanup.cleanup_stale_ingest_jobs",
|
||
return_value=([("job-1", "cel-1"), ("job-2", "")], ["a-1"]),
|
||
) as m_jobs,
|
||
patch(
|
||
"packages.application.ingest_orphan_cleanup.cleanup_orphan_processing_assets",
|
||
return_value=["a-2"],
|
||
) as m_assets,
|
||
patch(
|
||
"packages.shared.celery_orphan_guard.revoke_and_purge",
|
||
return_value=1,
|
||
) as m_revoke,
|
||
):
|
||
result = cleanup.scheduled_cleanup_stale_ingest_jobs()
|
||
|
||
m_db.assert_called_once()
|
||
m_jobs.assert_called_once()
|
||
assert m_jobs.call_args.kwargs["processing_timeout_minutes"] == 60
|
||
m_assets.assert_called_once()
|
||
m_revoke.assert_called_once()
|
||
# 队列名只传 transcode/celery(不传 generation)
|
||
assert m_revoke.call_args.kwargs["queue_names"] == ("transcode", "celery")
|
||
fake_session.close.assert_called_once()
|
||
assert result == {"stale_jobs": 2, "assets_to_error": 2, "purged_messages": 1}
|
||
|
||
|
||
def test_beat_cleanup_no_op_when_nothing_stale():
|
||
"""无孤儿时不调 revoke,返回全 0。"""
|
||
fake_session = MagicMock()
|
||
|
||
with (
|
||
patch("worker_app.db.SessionLocal", return_value=fake_session),
|
||
patch(
|
||
"packages.application.ingest_orphan_cleanup.cleanup_stale_ingest_jobs",
|
||
return_value=([], []),
|
||
),
|
||
patch(
|
||
"packages.application.ingest_orphan_cleanup.cleanup_orphan_processing_assets",
|
||
return_value=[],
|
||
),
|
||
patch("packages.shared.celery_orphan_guard.revoke_and_purge") as m_revoke,
|
||
):
|
||
result = cleanup.scheduled_cleanup_stale_ingest_jobs()
|
||
|
||
m_revoke.assert_not_called()
|
||
assert result == {"stale_jobs": 0, "assets_to_error": 0, "purged_messages": 0}
|