feat: show execution phases and verify responsive task queries
This commit is contained in:
1 parent
87ec3acc20
commit
bc6b726675
12 files changed
+342
-30
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||
from dx_productivity.trial_task_center.store import TaskStore
|
||||
|
||||
|
||||
def test_feedback_uses_executing_child_and_ignores_previous_run_progress(tmp_path):
|
||||
store = TaskStore(tmp_path / 'tasks.db')
|
||||
service = TaskCenterService(store, configure_logging(tmp_path / 'data'))
|
||||
task = service.create_task('board')
|
||||
child = service.for_project_task(task.task_id)
|
||||
child._batch_feedback = (task.task_id, None, '正在执行 board')
|
||||
service._task_queue_feedback = ('queue', task.task_id, 2, 3)
|
||||
path = child._quick_run_preparer.data_root / 'quick-run' / 'worker-progress.json'
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text(json.dumps({'stage': 'native_replace', 'stage_seconds': {'native_replace': 1.25}}))
|
||||
value = service.execution_feedback(None, started_after=0)
|
||||
assert value.task_id == task.task_id and (value.position, value.total) == (2, 3)
|
||||
assert value.message == '正在执行 board' and value.stage == 'native_replace'
|
||||
assert value.stage_seconds >= 1.25
|
||||
stale = service.execution_feedback(None, started_after=path.stat().st_mtime + 1)
|
||||
assert stale.stage == ''
|
||||
path.write_text('incomplete JSON')
|
||||
assert service.execution_feedback(None, started_after=0).stage == ''
|
||||
store.close()
|
||||
@@ -31,7 +31,7 @@ def browser(qtbot, tmp_path):
|
||||
yield window, service, tasks
|
||||
qtbot.waitUntil(lambda: not window._workers, timeout=5000)
|
||||
qtbot.waitUntil(lambda: not window._context_query.busy and not window._task_query.busy
|
||||
and not window._log_presenter.query.busy, timeout=5000)
|
||||
and not window._log_presenter.query.busy and not window._feedback_query.busy, timeout=5000)
|
||||
window.close()
|
||||
store.close()
|
||||
|
||||
@@ -167,3 +167,38 @@ def test_completion_names_execution_owner_when_browsing_another_task(browser, qt
|
||||
window._show_batch_result(result)
|
||||
assert a.name in window.run_panel.operator_band.text()
|
||||
assert not window.run_panel.toggle_log_button.isChecked()
|
||||
|
||||
|
||||
def test_completion_refresh_supersedes_a_pending_old_log_snapshot(browser, qtbot, monkeypatch, tmp_path):
|
||||
from types import SimpleNamespace
|
||||
window, service, (a, _) = browser
|
||||
path = tmp_path / 'data' / 'tasks' / a.task_id / 'events.jsonl'
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text('BEFORE\n')
|
||||
real = service.read_task_log
|
||||
entered, release = Event(), Event()
|
||||
first = True
|
||||
def delayed(task_id, **kwargs):
|
||||
nonlocal first
|
||||
page = real(task_id, **kwargs)
|
||||
if first:
|
||||
first = False
|
||||
entered.set()
|
||||
release.wait(1)
|
||||
return page
|
||||
monkeypatch.setattr(service, 'read_task_log', delayed)
|
||||
window.open_task(a.task_id)
|
||||
loaded(qtbot, window, a)
|
||||
window._begin_run(a.task_id)
|
||||
try:
|
||||
window._show_task_log()
|
||||
qtbot.waitUntil(entered.is_set)
|
||||
with path.open('a') as stream:
|
||||
stream.write('AFTER_COMPLETION\n')
|
||||
window._show_batch_result(SimpleNamespace(paused=False,
|
||||
progress=SimpleNamespace(saved_items=1, failed_items=0, no_match_items=0)))
|
||||
finally:
|
||||
release.set()
|
||||
window._finish_run()
|
||||
qtbot.waitUntil(lambda: not window._log_presenter.query.busy)
|
||||
assert 'AFTER_COMPLETION' in window.run_panel.log_view.toPlainText()
|
||||
Reference in new issue
Block a user