Live models: the labelled members are saved once per build and version, prepared by the indicators cycle and loaded by each API worker as it starts
This commit is contained in:
@@ -207,3 +207,36 @@ def test_without_a_recurrence_version_it_is_a_404(recurrence_client):
|
||||
recurrence_client.holder.production = None
|
||||
|
||||
assert recurrence_client.get("/cama/modelo/recurrencia").status_code == 404
|
||||
|
||||
|
||||
def test_the_members_are_computed_once_per_build_and_version_and_read_from_their_file_after(tmp_path, monkeypatch):
|
||||
"""Pins down: the first reader of a build's labelled members computes them from the build and leaves them in
|
||||
`INDICADORES_DIR/modelos`; the next reader (another worker, or the API after the cycle) reads that file without touching the
|
||||
build, and a new build replaces the old file. Fails if every worker reads the build again, or old builds pile up."""
|
||||
import pandas as pd
|
||||
from models.cama.survival import live
|
||||
from models.io import storage
|
||||
from webapi import model_analysis
|
||||
|
||||
monkeypatch.setenv("INDICADORES_DIR", str(tmp_path))
|
||||
reads = []
|
||||
|
||||
class Build:
|
||||
def __init__(self, domain, build_id):
|
||||
reads.append(build_id)
|
||||
|
||||
def frame(self):
|
||||
return pd.DataFrame()
|
||||
|
||||
def lineage(self):
|
||||
return {}
|
||||
|
||||
monkeypatch.setattr(storage, "KitBuild", Build)
|
||||
monkeypatch.setattr(live, "members", lambda spec, frame, lineage: pd.DataFrame({"pac_id": [1, 2], "stage": ["I", None]}))
|
||||
|
||||
first = model_analysis._members("spec", "cama", "survival", "3", 8)
|
||||
again = model_analysis._members("spec", "cama", "survival", "3", 8)
|
||||
model_analysis._members("spec", "cama", "survival", "3", 9)
|
||||
|
||||
assert reads == [8, 9] and again.equals(first)
|
||||
assert [p.name for p in (tmp_path / "modelos").iterdir()] == ["cama-survival-v3-armado9.parquet"]
|
||||
|
||||
Reference in New Issue
Block a user