fix: close batch execution and recovery lifecycle
This commit is contained in:
1 parent
b19afc6a53
commit
d9cf6a07e9
91 files changed
+5779
-454
No files matched your search
@@ -0,0 +1,63 @@
|
||||
"""Task categories follow committed receipts before the whole batch releases."""
|
||||
from threading import Event
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
from dx_productivity.trial_task_center.models import TaskStatus
|
||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||
from dx_productivity.trial_task_center.batch_resources import BatchResourceCleanupError
|
||||
|
||||
|
||||
def visible_ids(panel):
|
||||
return [panel.list.item(index).data(Qt.ItemDataRole.UserRole) for index in range(panel.list.count())]
|
||||
|
||||
|
||||
def test_completed_task_moves_category_while_next_task_is_still_executing(ui, qtbot, monkeypatch):
|
||||
window=ui.window
|
||||
first,second=ui.tasks
|
||||
waiting,release=Event(),Event()
|
||||
execute=TaskCenterService.execute_quick_run_queue
|
||||
def hold_second(service, task_id, **options):
|
||||
if task_id==second.task_id:
|
||||
waiting.set()
|
||||
assert release.wait(10), 'test did not release its controlled second task'
|
||||
return execute(service, task_id, **options)
|
||||
monkeypatch.setattr(TaskCenterService,'execute_quick_run_queue',hold_second)
|
||||
window._quick_run_confirmer=lambda *_args:True
|
||||
try:
|
||||
window._execute_project_tasks()
|
||||
qtbot.waitUntil(waiting.is_set, timeout=5000)
|
||||
assert ui.store.get_task(first.task_id).status is TaskStatus.COMPLETED
|
||||
ui.open(second)
|
||||
window.task_list.filter.setCurrentIndex(window.task_list.filter.findData('completed'))
|
||||
qtbot.waitUntil(lambda:visible_ids(window.task_list)==[first.task_id], timeout=3000)
|
||||
assert window._workers and window._batch_stop is not None
|
||||
assert window._task_id==second.task_id
|
||||
assert ui.store.get_task(second.task_id).status is not TaskStatus.COMPLETED
|
||||
assert len(ui.calls)==1
|
||||
finally:
|
||||
release.set()
|
||||
ui.settle()
|
||||
assert len(ui.calls)==2
|
||||
assert set(visible_ids(window.task_list))=={first.task_id,second.task_id}
|
||||
|
||||
|
||||
def test_resource_error_after_business_completion_refreshes_categories(ui):
|
||||
window=ui.window
|
||||
first=ui.tasks[0]
|
||||
window._begin_run(first.task_id)
|
||||
window._quick_run_timer.stop() # The final error path must refresh even without a timer tick.
|
||||
window.task_list.filter.setCurrentIndex(window.task_list.filter.findData('completed'))
|
||||
def execute_then_fail_release():
|
||||
progress=ui.service.quick_run_progress(first.task_id)
|
||||
expected=(str(progress.next_project_path),progress.next_old_part_number,
|
||||
progress.next_new_part_number,'preserve')
|
||||
ui.service.execute_quick_run_queue(first.task_id,expected_item=expected,
|
||||
stop_event=window._batch_stop)
|
||||
raise BatchResourceCleanupError('controlled desktop release failure after task completion')
|
||||
window._run_async(execute_then_fail_release,lambda _:None,expected_task_id=first.task_id)
|
||||
ui.settle()
|
||||
assert ui.store.get_task(first.task_id).status is TaskStatus.COMPLETED
|
||||
assert visible_ids(window.task_list)==[first.task_id]
|
||||
assert window._batch_stop is None
|
||||
assert len(ui.calls)==1
|
||||
assert 'controlled desktop release failure' in window.run_panel.operator_band.text()
|
||||
@@ -28,10 +28,14 @@ def visible_ids(panel):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('category','expected'),[
|
||||
('all',['draft','ready','running','paused','completed','failed']),
|
||||
('unfinished',['draft','ready','running','paused','failed']),
|
||||
('all',['draft','ready','running','paused','completed','failed','blocked']),
|
||||
('unfinished',['draft','ready','running','paused','failed','blocked']),
|
||||
('pending',['draft','ready']),
|
||||
('running',['running']),
|
||||
('paused',['paused']),
|
||||
('completed',['completed']),
|
||||
('failed',['failed']),
|
||||
('blocked',['blocked']),
|
||||
])
|
||||
def test_visible_status_category_filters_task_list(navigation,category,expected):
|
||||
panel,tasks,opened=navigation
|
||||
@@ -89,3 +93,36 @@ def test_recycle_bin_ignores_active_status_category(ui):
|
||||
assert panel.filter.isEnabled()
|
||||
assert panel.filter.currentData()=='completed'
|
||||
assert visible_ids(panel)==[]
|
||||
|
||||
|
||||
def test_retryable_failure_is_in_failed_category_and_never_displayed_as_running(navigation):
|
||||
panel,tasks,opened=navigation
|
||||
failed = replace(tasks[2], summary='current-sheet quick-run queue completed with retryable failures')
|
||||
panel.populate(tuple(failed if task.task_id == failed.task_id else task for task in tasks))
|
||||
panel.filter.setCurrentIndex(panel.filter.findData('failed'))
|
||||
assert visible_ids(panel)==['running','failed']
|
||||
assert panel.list.item(0).text().splitlines()[-1]=='失败'
|
||||
panel.filter.setCurrentIndex(panel.filter.findData('running'))
|
||||
assert visible_ids(panel)==[]
|
||||
assert failed.status is TaskStatus.RUNNING # Display classification does not authorize a retry.
|
||||
|
||||
|
||||
def test_status_refresh_preserves_multiple_selected_tasks(navigation):
|
||||
panel,tasks,opened=navigation
|
||||
panel.select_all_tasks()
|
||||
updated=tuple(replace(task,status=TaskStatus.COMPLETED) if task.task_id=='ready' else task for task in tasks)
|
||||
panel.populate(updated,selected_task_id='ready')
|
||||
assert {item.data(Qt.ItemDataRole.UserRole) for item in panel.list.selectedItems()} == {
|
||||
task.task_id for task in tasks}
|
||||
|
||||
|
||||
def test_status_refresh_does_not_reselect_a_current_item_the_user_deselected(navigation):
|
||||
panel,tasks,opened=navigation
|
||||
panel.select_all_tasks()
|
||||
panel.list.currentItem().setSelected(False)
|
||||
before={item.data(Qt.ItemDataRole.UserRole) for item in panel.list.selectedItems()}
|
||||
assert 'ready' not in before
|
||||
updated=tuple(replace(task,status=TaskStatus.COMPLETED) if task.task_id=='ready' else task for task in tasks)
|
||||
panel.populate(updated,selected_task_id='ready')
|
||||
assert {item.data(Qt.ItemDataRole.UserRole) for item in panel.list.selectedItems()}==before
|
||||
assert panel.current_task_id()=='ready'
|
||||
Reference in new issue
Block a user