Stream job logs from current offset
This commit is contained in:
@@ -1,6 +1,38 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.jobs import default_conda_env_for_job
|
||||
from app.main import _job_with_progress, app
|
||||
|
||||
|
||||
def test_mmseg_jobs_use_mmseg_conda_env_by_default():
|
||||
assert default_conda_env_for_job("mmseg.train") == "seg_mmcv"
|
||||
assert default_conda_env_for_job("segmodel.train") == "seg_smp"
|
||||
|
||||
|
||||
def test_job_progress_reports_log_size(tmp_path):
|
||||
log_path = tmp_path / "job.log"
|
||||
log_path.write_text("line one\nline two\n", encoding="utf-8")
|
||||
job = {"id": "job1", "status": "running", "log_path": str(log_path)}
|
||||
|
||||
enriched = _job_with_progress(job, include_log_tail=True)
|
||||
|
||||
assert enriched["log_size"] == log_path.stat().st_size
|
||||
assert enriched["log_tail"] == "line one\nline two\n"
|
||||
|
||||
|
||||
def test_job_events_respect_log_offset(tmp_path, monkeypatch):
|
||||
from app import main
|
||||
|
||||
log_path = tmp_path / "job.log"
|
||||
old_chunk = "old chunk\n"
|
||||
log_path.write_text(old_chunk + "new chunk\n", encoding="utf-8")
|
||||
|
||||
def fake_get_job(job_id):
|
||||
return {"id": job_id, "status": "success", "log_path": str(log_path)}
|
||||
|
||||
monkeypatch.setattr(main.db, "get_job", fake_get_job)
|
||||
response = TestClient(app).get(f"/api/jobs/job1/events?offset={len(old_chunk.encode('utf-8'))}")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "new chunk" in response.text
|
||||
assert "old chunk" not in response.text
|
||||
|
||||
Reference in New Issue
Block a user