test_sync_multi_demand_pool.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """需求池同步内部子阶段的异常隔离测试。"""
  2. from __future__ import annotations
  3. from unittest.mock import MagicMock, patch
  4. from supply_infra.scheduler.jobs.demand_pool.sync import _classify_words
  5. @patch(
  6. "supply_infra.scheduler.jobs.demand_pool.sync.classify_demand_words"
  7. )
  8. @patch(
  9. "supply_infra.scheduler.jobs.demand_pool.sync.DemandBelongCategoryRepository"
  10. )
  11. @patch(
  12. "supply_infra.scheduler.jobs.demand_pool.sync.MultiDemandPoolDiRepository"
  13. )
  14. @patch("supply_infra.scheduler.jobs.demand_pool.sync.get_session")
  15. def test_classification_batch_failure_continues_remaining_batches(
  16. mock_get_session,
  17. mock_pool_repo_cls,
  18. mock_belong_repo_cls,
  19. mock_classify,
  20. ) -> None:
  21. mock_get_session.return_value.__enter__.return_value = MagicMock()
  22. mock_pool_repo_cls.return_value.list_demand_names_by_biz_dt.return_value = [
  23. f"需求{i:03d}" for i in range(120)
  24. ]
  25. mock_belong_repo_cls.return_value.get_existing_names.return_value = set()
  26. mock_classify.side_effect = [RuntimeError("first batch failed"), None, None]
  27. result = _classify_words("20260721")
  28. assert mock_classify.call_count == 3
  29. assert result["success"] is False
  30. assert result["batches"] == 3
  31. assert result["failed_batches"] == [
  32. {"batch": 1, "size": 50, "error": "first batch failed"}
  33. ]