Improve ingestion concurrency safety and batch transaction robustness
This commit is contained in:
@ -26,6 +26,15 @@ def test_run_full_sync_creates_domain_objects(settings):
|
||||
assert PlayerSeason.objects.count() >= 1
|
||||
assert PlayerSeasonStats.objects.count() >= 1
|
||||
assert Player.objects.filter(origin_competition__isnull=False).exists()
|
||||
assert run.context.get("completed_steps") == [
|
||||
"competitions",
|
||||
"teams",
|
||||
"seasons",
|
||||
"players",
|
||||
"player_stats",
|
||||
"player_careers",
|
||||
]
|
||||
assert run.context.get("source_counts", {}).get("players", 0) >= 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@ -215,3 +224,24 @@ def test_balldontlie_sync_idempotency_with_stable_payload(monkeypatch):
|
||||
}
|
||||
|
||||
assert counts_first == counts_second
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_batch_transactions_preserve_prior_step_progress_on_failure(settings, monkeypatch):
|
||||
settings.PROVIDER_DEFAULT_NAMESPACE = "mvp_demo"
|
||||
|
||||
def boom(*args, **kwargs):
|
||||
raise RuntimeError("teams-sync-failed")
|
||||
|
||||
monkeypatch.setattr("apps.ingestion.services.sync._sync_teams", boom)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
run_sync_job(provider_namespace="mvp_demo", job_type=IngestionRun.JobType.FULL_SYNC)
|
||||
|
||||
run = IngestionRun.objects.order_by("-id").first()
|
||||
assert run is not None
|
||||
assert run.status == IngestionRun.RunStatus.FAILED
|
||||
assert Competition.objects.exists()
|
||||
assert Team.objects.count() == 0
|
||||
assert run.context.get("completed_steps") == ["competitions"]
|
||||
assert "Unhandled ingestion error" in run.error_summary
|
||||
|
||||
Reference in New Issue
Block a user