Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/test_worker_oneshot_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""One-shot worker must exit 0 after a successful pass (#168)."""

from __future__ import annotations

import sys
from pathlib import Path
from unittest import mock

import pytest

ROOT = Path(__file__).resolve().parents[1] / "validator" / "src"
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))


def test_oneshot_exits_zero_even_when_work_was_done(monkeypatch):
import eval_backend.worker as worker

monkeypatch.setattr(
worker,
"Settings",
mock.Mock(load=mock.Mock(return_value=mock.Mock(
ensure_dirs=mock.Mock(),
))),
)
monkeypatch.setattr(worker, "build_engine", mock.Mock())
monkeypatch.setattr(worker, "Base", mock.Mock(metadata=mock.Mock(create_all=mock.Mock())))
monkeypatch.setattr(worker, "ensure_schema", mock.Mock())
monkeypatch.setattr(worker, "build_session_factory", mock.Mock(return_value=object()))
monkeypatch.setattr(worker, "process_once", mock.Mock(return_value=1))
monkeypatch.setattr(sys, "argv", ["worker"])

with pytest.raises(SystemExit) as ei:
worker.main()
assert ei.value.code == 0
5 changes: 4 additions & 1 deletion validator/src/eval_backend/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ def main() -> None:
session_factory = build_session_factory(engine)

if not args.loop:
raise SystemExit(process_once(session_factory, settings))
# process_once returns a "did work" signal (1/0), not an exit status.
# One-shot success must exit 0 whether or not the queue had a job (#168).
process_once(session_factory, settings)
raise SystemExit(0)

while True:
processed = process_once(session_factory, settings)
Expand Down
Loading