fix: hold batch admission through startup recovery

This commit is contained in:
阿白叔 committed 2026-10-23 16:00:18 +08:00
1 parent 1baf908ba4
commit ba5b13667b
3 files changed
+54 -14

No files matched your search

+32
View File
@@ -90,6 +90,38 @@ def test_cancelled_request_does_not_launch_supervisor(tmp_path):
assert not (tmp_path/'batch-resources').exists()
def test_startup_recovery_holds_admission_until_runner_initialized(tmp_path, monkeypatch):
from dx_productivity.trial_task_center import service as module
from dx_productivity.trial_task_center.batch_supervisor import assert_supervisor_idle
from dx_productivity.trial_task_center.errors import TaskCenterError
from dx_productivity.trial_task_center.logging_setup import configure_logging
from dx_productivity.trial_task_center.store import TaskStore
checked = []
def runner(*args, **kwargs):
with pytest.raises(TaskCenterError, match='supervisor_busy'):
assert_supervisor_idle(tmp_path)
checked.append(True)
return object()
monkeypatch.setattr(module, 'TrialRunner', runner)
store = TaskStore(tmp_path/'task-center.db')
try:
module.TaskCenterService(store, configure_logging(tmp_path))
assert checked == [True]
assert_supervisor_idle(tmp_path)
finally:
store.close()
def test_crashed_legacy_task_protects_actual_root_without_replay(tmp_path):
from dx_productivity.trial_task_center.batch_supervisor import _mark_interrupted
journal = {'version': 1, 'batch_id': 'a'*32, 'attempt_id': 'b'*32,
'operation': 'execute_task_queue', 'task_ids': ['legacy'], 'state': 'running',
'uncertainty_roots': {'legacy': str(tmp_path)}}
_mark_interrupted(tmp_path, journal, 'missing final result')
assert (tmp_path/'quick-run/uncertain.flag').exists()
assert not (tmp_path/'tasks/legacy/quick-run/uncertain.flag').exists()
def test_parent_job_cleanup_failure_preserves_result_and_can_retry_resources_only(tmp_path, monkeypatch):
from dx_productivity.trial_task_center.batch_supervisor import run_supervised
from dx_productivity.trial_task_center.isolated_desktop import _Win32Api