fix: resume frozen task queue after verified resource release
Core regression / Python core, intervention UI and release configuration (push) Successful in 5m2s
Core regression / JavaScript syntax (push) Successful in 7s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m32s
Core regression / JavaScript syntax (pull_request) Successful in 8s
Core regression / Python core, intervention UI and release configuration (push) Successful in 5m2s
Core regression / JavaScript syntax (push) Successful in 7s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 5m32s
Core regression / JavaScript syntax (pull_request) Successful in 8s
This commit is contained in:
1 parent
d0bbc73da3
commit
6d45ea1fa0
12 files changed
+1259
-14
No files matched your search
@@ -96,6 +96,30 @@ def test_inspect_accepts_frozen_workspace_checkpoint(project_service):
|
||||
assert result['remaining_task_ids'] == ids
|
||||
|
||||
|
||||
def test_inspect_restores_a_legacy_resource_pause_only_from_its_original_batch(project_service, monkeypatch):
|
||||
from dx_productivity.trial_task_center import task_queue
|
||||
service, _, data, ids, hashes = project_service
|
||||
journal = RunJournal(data)
|
||||
token, batch_id = 'a' * 32, 'b' * 32
|
||||
journal.begin(token, ids, hashes)
|
||||
checkpoint(data, token, ids, hashes, {ids[0]: 'blocked'})
|
||||
path = data / 'task-queues' / (token + '.json')
|
||||
state = json.loads(path.read_bytes())
|
||||
path.write_text(json.dumps(dict(state, phase='primary')), encoding='utf-8')
|
||||
journal.finish(token, {'status': 'blocked', 'paused': True, 'user_pause_requested': False})
|
||||
archive = data / 'batch-resources' / batch_id / 'result.json'
|
||||
archive.parent.mkdir(parents=True)
|
||||
archive.touch()
|
||||
monkeypatch.setattr(task_queue, 'resource_pause_admitted', lambda root, owner, tasks, plan:
|
||||
TaskQueueResult(token, (), True, ids[0]) if owner == batch_id and tuple(ids) == tasks and hashes == plan else False)
|
||||
result = journal.inspect(service, token)
|
||||
assert result['resource_batch_id'] == batch_id
|
||||
assert result['isolated_task_ids'] == ids[:1]
|
||||
assert result['remaining_task_ids'] == ids[1:]
|
||||
journal.finish(token, {'status': 'blocked', 'paused': True, 'user_pause_requested': True})
|
||||
assert journal.inspect(service, token)['resource_batch_id'] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('interrupted', [False, True])
|
||||
def test_shared_safe_primary_failure_can_hold_remaining_commands_on_resume(project_service, monkeypatch, interrupted):
|
||||
from dataclasses import replace
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import hashlib
|
||||
import json
|
||||
from threading import Event
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from dx_productivity.trial_task_center import task_queue
|
||||
from dx_productivity.trial_task_center.supervisor_protocol import encode
|
||||
from dx_productivity.trial_task_center.task_queue import TaskQueueEntry, TaskQueueResult
|
||||
|
||||
|
||||
@pytest.mark.parametrize('release', [True, False])
|
||||
@pytest.mark.parametrize('user_pause', [False, True])
|
||||
def test_normal_supervised_queue_reuses_original_queue_after_resource_pause(tmp_path, monkeypatch, release, user_pause):
|
||||
ids = ('A', 'B', 'C')
|
||||
token = 'a' * 32
|
||||
hashes = dict.fromkeys(ids, 'f' * 64)
|
||||
result = TaskQueueResult(token, (TaskQueueEntry('A', 'completed'), TaskQueueEntry('B', 'blocked'),
|
||||
TaskQueueEntry('C', 'pending')), True, 'B')
|
||||
done = TaskQueueResult(token, (result.entries[0], result.entries[1], TaskQueueEntry('C', 'completed')), False)
|
||||
calls = []
|
||||
service = SimpleNamespace(_supervised=True, _logging=SimpleNamespace(root=tmp_path))
|
||||
stop = Event()
|
||||
|
||||
def supervise(operation, arguments, **kwargs):
|
||||
calls.append(arguments)
|
||||
if user_pause:
|
||||
stop.set()
|
||||
return result if len(calls) == 1 else done
|
||||
|
||||
service._supervise = supervise
|
||||
service._last_supervisor_batch_id = 'b' * 32
|
||||
service.pending_batch_resources = lambda: ()
|
||||
monkeypatch.setattr(task_queue, 'resource_pause_admitted', lambda *args: release, raising=False)
|
||||
resumed = release and not user_pause
|
||||
assert task_queue.execute_task_queue(service, ids, stop_event=stop, checkpoint_id=token,
|
||||
expected_plan_hashes=hashes) == (done if resumed else result)
|
||||
assert [call['checkpoint_id'] for call in calls] == ([token, None] if resumed else [token])
|
||||
if resumed:
|
||||
assert calls[-1]['queue_id'] == token
|
||||
assert calls[-1]['expected_plan_hashes'] == hashes
|
||||
|
||||
|
||||
@pytest.mark.parametrize('reason', [None, 'unknown_writer', 'cancel', 'consumed', 'unknown_pause'])
|
||||
def test_original_receipt_must_prove_resource_pause_and_cannot_be_consumed_again(tmp_path, monkeypatch, reason):
|
||||
from dx_productivity.trial_task_center import batch_resources
|
||||
|
||||
batch_id, attempt, queue = 'b' * 32, 'c' * 32, 'a' * 32
|
||||
ids, hashes = ('A', 'B'), {'A': '01', 'B': '02'}
|
||||
entries = (TaskQueueEntry('A', 'blocked'), TaskQueueEntry('B', 'pending'))
|
||||
result = TaskQueueResult(queue, entries, True, 'A')
|
||||
folder = tmp_path / 'batch-resources' / batch_id
|
||||
request = {'batch_id': batch_id, 'attempt_id': attempt, 'operation': 'execute_task_queue', 'root': str(tmp_path),
|
||||
'arguments': encode({'task_ids': ids, 'queue_id': None, 'checkpoint_id': queue,
|
||||
'expected_plan_hashes': hashes})}
|
||||
batch_resources.write_record(folder / 'request.json', request)
|
||||
digest = hashlib.sha256((folder / 'request.json').read_bytes()).hexdigest()
|
||||
process = {'pid': 17, 'creation_time': 'worker'}
|
||||
batch_resources.write_record(folder / 'supervisor.json', {'version': 1, 'batch_id': batch_id, 'attempt_id': attempt,
|
||||
'operation': 'execute_task_queue', 'task_ids': list(ids), 'parent_process': process,
|
||||
'process': process, 'state': 'finished', 'request_sha256': digest})
|
||||
payload = {'business_succeeded': True, 'status': 'ok', 'result': encode(result)}
|
||||
if reason != 'unknown_pause':
|
||||
payload['resource_warning'] = {'state': 'isolated', 'owned_writers_exited': True}
|
||||
batch_resources.write_record(folder / 'result.json', {'version': 1, 'batch_id': batch_id, 'attempt_id': attempt,
|
||||
'generation': 1, 'sequence': 1, 'type': 'result', 'payload': payload})
|
||||
state = {'version': 1, 'task_ids': list(ids), 'plan_hashes': hashes, 'phase': 'primary',
|
||||
'entries': {entry.task_id: {'state': entry.state, 'message': entry.message} for entry in entries}}
|
||||
if reason == 'consumed':
|
||||
state['consumed_resource_pauses'] = {batch_id: 'A'}
|
||||
if reason == 'cancel':
|
||||
(folder / 'cancel.json').write_text(json.dumps({'batch_id': batch_id}))
|
||||
batch_resources.write_record(tmp_path / 'task-queues' / (queue + '.json'), state)
|
||||
monkeypatch.setattr(batch_resources, '_process_gone', lambda _: reason != 'unknown_writer')
|
||||
assert task_queue.resource_pause_admitted(tmp_path, batch_id, ids, hashes) == (False if reason else result)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('text', ['', 'KEY iCDBDir database', 'KEY iCDBDir "database"\nKEY iCDBDir "../other"'])
|
||||
def test_ambiguous_or_missing_write_sources_cannot_be_used_to_resume(tmp_path, text):
|
||||
from dx_productivity.trial_task_center.project_isolation import write_sources
|
||||
|
||||
project = tmp_path / 'board.prj'
|
||||
project.write_text(text)
|
||||
with pytest.raises(ValueError, match='iCDBDir'):
|
||||
write_sources(project, strict=True)
|
||||
Reference in new issue
Block a user