85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture()
|
|
def store(tmp_path, monkeypatch):
|
|
db_url = f"sqlite:///{(tmp_path / 'digitador.db').as_posix()}"
|
|
monkeypatch.setenv("DATABASE_URL", db_url)
|
|
for name in ["infrastructure.database", "infrastructure.store"]:
|
|
if name in sys.modules:
|
|
importlib.reload(sys.modules[name])
|
|
else:
|
|
importlib.import_module(name)
|
|
|
|
from infrastructure import database as db
|
|
|
|
importlib.reload(db)
|
|
import infrastructure.store as store_mod
|
|
|
|
importlib.reload(store_mod)
|
|
from domain.models import JobStatus
|
|
|
|
return store_mod.JobStore(), JobStatus
|
|
|
|
|
|
def test_distributed_parent_uses_agent_counters_and_live_progress(store):
|
|
job_store, JobStatus = store
|
|
parent = job_store.create_job(
|
|
None,
|
|
"uploads/parent/input.csv",
|
|
"input.csv",
|
|
shard_count=2,
|
|
result={"total_rows": 8, "processed": 0},
|
|
status=JobStatus.PENDING.value,
|
|
)
|
|
first = job_store.create_job(
|
|
"PC-01",
|
|
"uploads/first/input.csv",
|
|
parent_digitador_job_id=parent.id,
|
|
shard_index=0,
|
|
shard_count=2,
|
|
result={"total": 4, "processed": 2},
|
|
status=JobStatus.RUNNING.value,
|
|
)
|
|
second = job_store.create_job(
|
|
"PC-02",
|
|
"uploads/second/input.csv",
|
|
parent_digitador_job_id=parent.id,
|
|
shard_index=1,
|
|
shard_count=2,
|
|
result={"total": 4, "processed": 1},
|
|
status=JobStatus.RUNNING.value,
|
|
)
|
|
|
|
live = job_store.refresh_parent_from_shards(parent.id)
|
|
assert live is not None
|
|
assert live.result["processed"] == 3
|
|
assert live.result["total"] == 8
|
|
|
|
job_store.patch_job(
|
|
first.id,
|
|
status=JobStatus.COMPLETED.value,
|
|
result={
|
|
"total": 4,
|
|
"exitosos": 1,
|
|
"fallidos": 2,
|
|
"omitidos": 1,
|
|
"timeouts": 1,
|
|
"existentes": 1,
|
|
"uploaded_count": 3,
|
|
},
|
|
)
|
|
live = job_store.refresh_parent_from_shards(parent.id)
|
|
assert live is not None
|
|
assert live.result["processed"] == 5
|
|
assert live.result["exitosos"] == 1
|
|
assert live.result["fallidos"] == 2
|
|
assert live.result["existentes"] == 1
|
|
assert live.result["timeouts"] == 1
|
|
assert live.result["uploaded_count"] == 3
|