Test platforms start with MLflow's schema in place, built once per session
The SQLite TEA gate failed in training: the API and the run opened the new MLflow SQLite file together, both ran its migrations, and one failed with "duplicate column name: step". Deployments use an MLflow server, so only tests had the race.
This commit is contained in:
+21
@@ -1,12 +1,14 @@
|
||||
"""Shared by every test: the synthetic hospital, a fresh platform per test (SQLite and
|
||||
PostgreSQL), and the platform's own processes, run the way they run in production."""
|
||||
|
||||
import atexit
|
||||
import json
|
||||
import os
|
||||
import secrets
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
@@ -55,6 +57,7 @@ def _platform(kind: str, tmp_path: Path) -> SimpleNamespace:
|
||||
"MLFLOW_TRACKING_URI": f"sqlite:///{tmp_path / 'mlflow.db'}",
|
||||
"EXECUTION_MODE": "sync",
|
||||
}
|
||||
_mlflow_schema(env["MLFLOW_TRACKING_URI"], tmp_path)
|
||||
if kind == "sqlite":
|
||||
url = env["PLATFORM_DATABASE_URL"] = f"sqlite:///{tmp_path / 'platform.db'}"
|
||||
attach = [f"ATTACH '{tmp_path}/platform__{s}.db' AS {s}" for s in SCHEMAS]
|
||||
@@ -89,6 +92,24 @@ def _platform(kind: str, tmp_path: Path) -> SimpleNamespace:
|
||||
) # fmt: skip
|
||||
|
||||
|
||||
_MLFLOW_TEMPLATE: list[Path] = [] # MLflow's empty SQLite schema, built once per session
|
||||
|
||||
|
||||
def _mlflow_schema(uri: str, tmp_path: Path) -> None:
|
||||
"""Start the platform with MLflow's schema in place: when the API and a run open a new
|
||||
file at the same time, both run its migrations and one fails (`duplicate column name:
|
||||
step`). The schema is built once (slow: every migration) and copied for each platform."""
|
||||
if not _MLFLOW_TEMPLATE:
|
||||
from mlflow.store.tracking.sqlalchemy_store import SqlAlchemyStore
|
||||
|
||||
folder = tempfile.mkdtemp(prefix="mlflow-schema-")
|
||||
atexit.register(shutil.rmtree, folder, ignore_errors=True)
|
||||
template = Path(folder) / "mlflow.db"
|
||||
SqlAlchemyStore(f"sqlite:///{template}", template.parent.as_uri()).engine.dispose()
|
||||
_MLFLOW_TEMPLATE.append(template)
|
||||
shutil.copy(_MLFLOW_TEMPLATE[0], uri.removeprefix("sqlite:///"))
|
||||
|
||||
|
||||
def _free_port() -> int:
|
||||
with socket.socket() as s:
|
||||
s.bind(("127.0.0.1", 0))
|
||||
|
||||
Reference in New Issue
Block a user