fix: address PR 47 batch execution and resource audit
Core regression / Python core, intervention UI and release configuration (push) Failing after 7m8s
Core regression / JavaScript syntax (push) Successful in 8s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 7m12s
Core regression / JavaScript syntax (pull_request) Successful in 8s
Core regression / Python core, intervention UI and release configuration (push) Failing after 7m8s
Core regression / JavaScript syntax (push) Successful in 8s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 7m12s
Core regression / JavaScript syntax (pull_request) Successful in 8s
This commit is contained in:
1 parent
392ae365da
commit
2a89d6fdd4
29 files changed
+1449
-298
No files matched your search
@@ -188,8 +188,11 @@ def test_missing_confirmed_manifest_cannot_fall_back_to_legacy_retry(confirmed_i
|
||||
|
||||
|
||||
def test_incident_dispatch_failure_exports_original_batch_revision(confirmed_incident_batch, monkeypatch):
|
||||
from hashlib import sha256
|
||||
from dx_productivity.dsh.execution_runs import _republish_incident_batch_summary
|
||||
from dx_productivity.trial_task_center.batch_resources import write_record
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
from dx_productivity.trial_task_center.supervisor_protocol import VERSION, encode
|
||||
|
||||
case, held = confirmed_incident_batch
|
||||
held['value'] = False
|
||||
@@ -208,8 +211,17 @@ def test_incident_dispatch_failure_exports_original_batch_revision(confirmed_inc
|
||||
|
||||
def failed_dispatch(item, **controls):
|
||||
controls['revalidate']()
|
||||
directory = root / 'batch-resources' / batch_id
|
||||
request = directory / 'request.json'
|
||||
header = {'version': VERSION, 'batch_id': batch_id, 'attempt_id': '5' * 32,
|
||||
'operation': 'execute_quick_run_queue', 'task_ids': [item]}
|
||||
write_record(request, dict(header, root=str(root),
|
||||
arguments=encode({'task_id': item, 'expected_item': controls['expected_item']})))
|
||||
write_record(directory / 'supervisor.json', dict(header, state='starting',
|
||||
request_sha256=sha256(request.read_bytes()).hexdigest(),
|
||||
parent_process={'pid': 1, 'creation_time': 'test'}))
|
||||
controls['before_launch'](batch_id)
|
||||
dispatched.append(item)
|
||||
service._last_supervisor_batch_id = batch_id
|
||||
raise TaskCenterError('supervisor_interrupted', 'worker ended without a durable result')
|
||||
|
||||
monkeypatch.setattr(service, 'execute_quick_run_queue', failed_dispatch)
|
||||
|
||||
@@ -78,21 +78,13 @@ def test_bound_receipt_preserves_verified_result_and_checks_resource_state(batch
|
||||
(TASK_ID, 'round', 'key', json.dumps({'target_scope': 'targets',
|
||||
'project_path': 'board.prj', 'schematic_name': 'MAIN', 'sheet_number': '1',
|
||||
'target_selectors': 'uid1\x1fR1'}), 'verified', 'a', 1, '{}'))
|
||||
current_service._last_supervisor_batch_id = BATCH_ID
|
||||
record = {'version': 1, 'session_id': BATCH_ID, 'kind': 'task_queue',
|
||||
'generation': 1, 'desktop': 'dx-' + BATCH_ID, 'state': resource_state, 'processes': [],
|
||||
'cad_pid': None, 'cad_guid': None, 'checkpoints': {}, 'retries': {}, 'timings': [],
|
||||
'release_proof': {'generation': 1, 'desktop_not_acquired': True},
|
||||
'cleanup': {'desktop_not_acquired': True, 'desktop_handle_closed': True,
|
||||
'owned_cleanup_complete': True}}
|
||||
batch_resources.write_record(data / 'batch-resources' / BATCH_ID / 'session.json', record)
|
||||
from dx_productivity.trial_task_center.supervisor_protocol import VERSION
|
||||
batch_resources.write_record(data / 'batch-resources' / BATCH_ID / 'supervisor.json',
|
||||
{'version': VERSION, 'batch_id': BATCH_ID, 'state': 'finished', 'outcome': 'ok',
|
||||
'operation': 'execute_task_queue', 'task_ids': [TASK_ID], 'attempt_id': '3' * 32,
|
||||
'request_sha256': '0' * 64, 'parent_process': {'pid': 1, 'creation_time': 'test'}})
|
||||
return TaskQueueResult(RUN_ID, (TaskQueueEntry(TASK_ID, 'completed'),), False,
|
||||
result = TaskQueueResult(RUN_ID, (TaskQueueEntry(TASK_ID, 'completed'),), False,
|
||||
netlist_verification={TASK_ID: {'status': 'verified', 'verified': True}})
|
||||
_durable_supervisor_result(data, result)
|
||||
path = data / 'batch-resources' / BATCH_ID / 'session.json'
|
||||
record = json.loads(path.read_bytes())
|
||||
batch_resources.write_record(path, dict(record, state=resource_state))
|
||||
return result
|
||||
|
||||
monkeypatch.setattr(execution_runs, 'execute_task_queue', dispatch)
|
||||
receipt = execution_runs.execute_confirmed_run(service, data, (TASK_ID,), report, Event(),
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import os
|
||||
import subprocess
|
||||
from threading import Event
|
||||
import zipfile
|
||||
|
||||
import pytest
|
||||
|
||||
from dx_productivity.dsh import execution_runs
|
||||
from dx_productivity.dsh.run_journal import RunJournal
|
||||
from dx_productivity.trial_task_center import batch_resources, batch_summary
|
||||
from dx_productivity.trial_task_center.batch_admission import build_batch_admission
|
||||
from dx_productivity.trial_task_center.diagnostics_bundle import export_diagnostic_bundle
|
||||
from dx_productivity.trial_task_center.supervisor_protocol import VERSION, encode
|
||||
from dx_productivity.trial_task_center.task_queue import TaskQueueEntry, TaskQueueResult
|
||||
from test_incident_rule_retry import confirmed_incident_batch, incident, rule_run
|
||||
from test_issue44_batch_receipt import (
|
||||
BATCH_ID, PLAN_HASHES, RUN_ID, TASK_ID, _durable_supervisor_result, batch,
|
||||
)
|
||||
from test_run_journal import project_service
|
||||
|
||||
|
||||
def _complete():
|
||||
return {'status': 'completed', 'execution_status': 'completed', 'queue_id': RUN_ID,
|
||||
'entries': [{'task_id': TASK_ID, 'state': 'completed', 'message': 'done'}],
|
||||
'netlist_verification': {TASK_ID: {'status': 'verified', 'verified': True}}}
|
||||
|
||||
|
||||
def _start(data, admission):
|
||||
batch_resources.write_record(data / 'batch-runs' / RUN_ID / 'manifest.json',
|
||||
dict(admission, run_id=RUN_ID))
|
||||
journal = RunJournal(data)
|
||||
journal.begin(RUN_ID, [TASK_ID], PLAN_HASHES)
|
||||
return journal
|
||||
|
||||
|
||||
def _supervised_complete(data):
|
||||
receipt = _complete()
|
||||
_durable_supervisor_result(data, TaskQueueResult(RUN_ID, (TaskQueueEntry(TASK_ID, 'completed', 'done'),),
|
||||
False, netlist_verification=receipt['netlist_verification']))
|
||||
batch_resources.write_record(data / 'task-queues' / (RUN_ID + '.json'),
|
||||
{'task_ids': [TASK_ID], 'plan_hashes': PLAN_HASHES, 'manifest_digest': 'd' * 64,
|
||||
'entries': {TASK_ID: {'state': 'completed', 'message': 'done'}}})
|
||||
return receipt
|
||||
|
||||
|
||||
def _update_json(path, **changes):
|
||||
batch_resources.write_record(path, dict(json.loads(path.read_bytes()), **changes))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('owns_desktop', [False, pytest.param(True,
|
||||
marks=pytest.mark.skipif(os.name != 'nt', reason='Windows desktop lifetime'))])
|
||||
def test_local_manifest_run_completes_from_its_actual_runtime_release(project_service, monkeypatch, owns_desktop):
|
||||
service, _, root, ids, _ = project_service
|
||||
task_id = ids[0]
|
||||
child = service.for_project_task(task_id)
|
||||
calls = []
|
||||
|
||||
def worker(command, timeout):
|
||||
job = command[-1]
|
||||
calls.append(job)
|
||||
with (Path(command[3]) / 'status.tsv').open('a', encoding='utf-8') as stream:
|
||||
stream.write(f'{job}\tno_match\tbatch_closed\tNo matching components\n')
|
||||
return subprocess.CompletedProcess(command, 0, '', '')
|
||||
|
||||
monkeypatch.setattr(child._quick_run_preparer, '_process_runner', worker)
|
||||
monkeypatch.setattr(child._quick_run_preparer, '_cscript_resolver', lambda: Path('cscript.exe'))
|
||||
if owns_desktop:
|
||||
execute = child.execute_quick_run_queue
|
||||
|
||||
def execute_on_desktop(task_id, *, runtime, **kwargs):
|
||||
runtime._ensure_desktop()
|
||||
return execute(task_id, runtime=runtime, **kwargs)
|
||||
|
||||
monkeypatch.setattr(child, 'execute_quick_run_queue', execute_on_desktop)
|
||||
admission = build_batch_admission(service, [task_id], scope_kind='selected')
|
||||
report = admission['execution_report']
|
||||
result = execution_runs.execute_confirmed_run(service, root, [task_id], report, Event(),
|
||||
RUN_ID, admission=admission)
|
||||
assert len(calls) == 1
|
||||
assert result['execution_status'] == 'completed'
|
||||
assert result['status'] == 'completed' and result['summary']['resource_state'] == 'released'
|
||||
assert result['summary']['resource']['evidence']
|
||||
assert result['tasks'][0]['no_match_items'] == 1
|
||||
assert bool(result['summary']['resource']['generations']) is owns_desktop
|
||||
journal = RunJournal(root)
|
||||
assert journal.get(RUN_ID)['status'] == 'completed'
|
||||
if not owns_desktop:
|
||||
proof = result['summary']['resource']['evidence'][0]
|
||||
with zipfile.ZipFile(export_diagnostic_bundle(root, root.parent / 'receipt-support.zip')) as bundle:
|
||||
assert json.loads(bundle.read(proof))['never_acquired'] is True
|
||||
(root / proof).unlink()
|
||||
journal.finish(RUN_ID, {key: value for key, value in result.items() if key != 'summary'})
|
||||
execution_runs.recover_batch_receipts(service, root)
|
||||
rebuilt = journal.batch_summary(RUN_ID)
|
||||
assert rebuilt['resource_state'] == 'unknown' and rebuilt['status'] == 'paused'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('already_summarized', [False, True])
|
||||
def test_incident_publication_preserves_the_recorded_elapsed_time(batch, already_summarized):
|
||||
service, _, data, _, admission = batch
|
||||
journal = _start(data, admission)
|
||||
receipt = _supervised_complete(data)
|
||||
journal.finish(RUN_ID, dict(receipt, elapsed_seconds=28.125))
|
||||
if already_summarized:
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
result = execution_runs._republish_incident_batch_summary(service, data, RUN_ID, receipt)
|
||||
assert result['elapsed_seconds'] == result['summary']['elapsed_seconds'] == 28.125
|
||||
assert journal.get(RUN_ID)['result']['elapsed_seconds'] == 28.125
|
||||
|
||||
|
||||
def test_recovery_retries_a_previously_unstable_snapshot_at_the_same_revision(batch, monkeypatch):
|
||||
service, _, data, _, admission = batch
|
||||
journal = _start(data, admission)
|
||||
receipt = _supervised_complete(data)
|
||||
journal.finish(RUN_ID, receipt)
|
||||
original = batch_summary._operation_sources
|
||||
generations = iter(range(3))
|
||||
|
||||
def changing(*args):
|
||||
rows, _, missing = original(*args)
|
||||
return rows, {TASK_ID: {'round_id': str(next(generations))}}, missing
|
||||
|
||||
with monkeypatch.context() as unstable:
|
||||
unstable.setattr(batch_summary, '_operation_sources', changing)
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
first = journal.batch_summary(RUN_ID)
|
||||
assert first['status'] == 'paused'
|
||||
assert {'code': 'batch_snapshot_unstable'} in first['reporting_errors']
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
recovered = journal.batch_summary(RUN_ID)
|
||||
assert recovered['status'] == 'completed'
|
||||
assert recovered['revision'] == first['revision'] + 1
|
||||
assert {'code': 'batch_snapshot_unstable'} not in recovered['reporting_errors']
|
||||
|
||||
|
||||
def test_generation_cannot_publish_released_without_physical_proof(batch):
|
||||
service, _, data, _, admission = batch
|
||||
journal = _start(data, admission)
|
||||
receipt = _supervised_complete(data)
|
||||
session = data / 'batch-resources' / BATCH_ID / 'session.json'
|
||||
_update_json(session, release_proof={}, cleanup={}, generation_releases=[
|
||||
{'generation': 1, 'desktop': 'dx-' + BATCH_ID, 'reason': 'unverified'}], generation=2)
|
||||
journal.finish(RUN_ID, receipt)
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
summary = journal.batch_summary(RUN_ID)
|
||||
assert summary['status'] == 'paused'
|
||||
assert {row['generation']: row['state'] for row in summary['resource']['generations']} == {
|
||||
1: 'unknown', 2: 'unknown'}
|
||||
|
||||
|
||||
def _quick_retry(data, retry_id, *, task_id=TASK_ID, expected_item=('p', 's', 'old', 'new')):
|
||||
_durable_supervisor_result(data, None, batch_id=retry_id)
|
||||
directory = data / 'batch-resources' / retry_id
|
||||
request = directory / 'request.json'
|
||||
_update_json(request, operation='execute_quick_run_queue', task_ids=[task_id],
|
||||
arguments=encode({'task_id': task_id, 'expected_item': expected_item}))
|
||||
_update_json(directory / 'supervisor.json', operation='execute_quick_run_queue', task_ids=[task_id],
|
||||
request_sha256=hashlib.sha256(request.read_bytes()).hexdigest())
|
||||
_update_json(directory / 'session.json', kind='quick_run_queue')
|
||||
return request
|
||||
|
||||
|
||||
@pytest.mark.parametrize('damaged_request', ['', 'request', 'request_and_digest'])
|
||||
def test_full_recovery_preserves_and_rechecks_the_bound_quick_run(batch, damaged_request):
|
||||
service, _, data, _, admission = batch
|
||||
journal = _start(data, admission)
|
||||
receipt = _supervised_complete(data)
|
||||
retry_id = '5' * 32
|
||||
retry_request = _quick_retry(data, retry_id)
|
||||
journal.finish(RUN_ID, receipt)
|
||||
execution_runs._record_incident_resource_link(data, RUN_ID, retry_id, TASK_ID, ('p', 's', 'old', 'new'))
|
||||
execution_runs._republish_incident_batch_summary(service, data, RUN_ID, receipt)
|
||||
assert retry_id in journal.batch_summary(RUN_ID)['resource_batch_ids']
|
||||
if damaged_request:
|
||||
_update_json(retry_request, arguments=encode({'task_id': TASK_ID, 'expected_item': ('other',)}))
|
||||
if damaged_request == 'request_and_digest':
|
||||
_update_json(retry_request.with_name('supervisor.json'),
|
||||
request_sha256=hashlib.sha256(retry_request.read_bytes()).hexdigest())
|
||||
journal.finish(RUN_ID, receipt) # No matching receipt revision, so startup rebuilds all sources.
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
summary = journal.batch_summary(RUN_ID)
|
||||
assert retry_id in summary['resource_batch_ids']
|
||||
assert summary['resource_state'] == ('unknown' if damaged_request else 'released')
|
||||
if not damaged_request:
|
||||
assert any(row['session_id'] == retry_id for row in summary['resource']['generations'])
|
||||
proof = f'batch-runs/{RUN_ID}/incident-resource-{retry_id}.json'
|
||||
with zipfile.ZipFile(export_diagnostic_bundle(data, data.parent / 'retry-support.zip')) as bundle:
|
||||
assert json.loads(bundle.read(proof))['task_id'] == TASK_ID
|
||||
|
||||
|
||||
def test_receipt_rebuild_preserves_supervisor_shutdown_failure_after_release(batch):
|
||||
service, _, data, _, admission = batch
|
||||
journal = _start(data, admission)
|
||||
_supervised_complete(data)
|
||||
supervisor = data / 'batch-resources' / BATCH_ID / 'supervisor.json'
|
||||
_update_json(supervisor, outcome='application_shutdown_failed')
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
summary = journal.batch_summary(RUN_ID)
|
||||
assert summary['execution_status'] == 'completed' and summary['resource_state'] == 'released'
|
||||
assert summary['status'] == 'failed' and summary['stop_reason'] == 'application_shutdown_failed'
|
||||
|
||||
|
||||
def test_recovery_rejects_success_when_the_supervisor_marked_the_business_uncertain(batch):
|
||||
service, _, data, _, admission = batch
|
||||
journal = _start(data, admission)
|
||||
_supervised_complete(data)
|
||||
supervisor = data / 'batch-resources' / BATCH_ID / 'supervisor.json'
|
||||
_update_json(supervisor, outcome='interrupted', business_uncertain=True)
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
summary = journal.batch_summary(RUN_ID)
|
||||
assert summary['status'] == 'interrupted'
|
||||
|
||||
|
||||
def test_shutdown_diagnostics_also_protect_old_supervisor_receipts(batch):
|
||||
service, _, data, _, admission = batch
|
||||
journal = _start(data, admission)
|
||||
_supervised_complete(data)
|
||||
session = data / 'batch-resources' / BATCH_ID / 'session.json'
|
||||
_update_json(session, cad_shutdown={'orderly_shutdown': False, 'forced_termination': True})
|
||||
execution_runs.recover_batch_receipts(service, data)
|
||||
summary = journal.batch_summary(RUN_ID)
|
||||
assert summary['execution_status'] == 'completed' and summary['resource_state'] == 'released'
|
||||
assert summary['status'] == 'failed' and summary['stop_reason'] == 'application_shutdown_failed'
|
||||
|
||||
|
||||
def test_local_retry_keeps_its_runtime_after_first_business_receipt_fails(confirmed_incident_batch, monkeypatch):
|
||||
case, held = confirmed_incident_batch
|
||||
held['value'] = False
|
||||
service, task_id, run_id, root = (case[key] for key in ('service', 'task_id', 'run_id', 'root'))
|
||||
manifest = json.loads((root / 'batch-runs' / run_id / 'manifest.json').read_bytes())
|
||||
checkpoint = root / 'task-queues' / (run_id + '.json')
|
||||
_update_json(checkpoint, manifest_digest=manifest['manifest_digest'])
|
||||
class FatalExit(BaseException):
|
||||
pass
|
||||
|
||||
def fail_first_receipt(*args):
|
||||
raise FatalExit('first business receipt write failed')
|
||||
|
||||
with monkeypatch.context() as damaged:
|
||||
damaged.setattr(RunJournal, 'finish', fail_first_receipt)
|
||||
with pytest.raises(FatalExit):
|
||||
incident(case)
|
||||
execution_runs.recover_batch_receipts(service, root)
|
||||
summary = RunJournal(root).batch_summary(run_id)
|
||||
assert summary['status'] == 'interrupted'
|
||||
retry_id, = summary['resource_batch_ids']
|
||||
evidence = root / summary['resource']['evidence'][0]
|
||||
binding = json.loads(evidence.read_bytes())
|
||||
assert binding['task_id'] == task_id and binding['session_id'] == retry_id
|
||||
assert binding['kind'] == 'quick_run_queue' and binding['never_acquired'] is True
|
||||
assert summary['resource_state'] == 'released'
|
||||
assert case['calls'] == ['OLD-OK', 'OLD-BAD', 'OLD-BAD']
|
||||
|
||||
|
||||
def test_local_retry_records_no_acquisition_after_an_explicit_precondition_error(
|
||||
confirmed_incident_batch, monkeypatch):
|
||||
case, held = confirmed_incident_batch
|
||||
held['value'] = False
|
||||
service, task_id, run_id, root = (case[key] for key in ('service', 'task_id', 'run_id', 'root'))
|
||||
folder = root / 'batch-runs' / run_id
|
||||
manifest = json.loads((folder / 'manifest.json').read_bytes())
|
||||
_update_json(root / 'task-queues' / (run_id + '.json'), manifest_digest=manifest['manifest_digest'])
|
||||
store = service.for_project_task(task_id)._store
|
||||
original = store.has_active_project
|
||||
monkeypatch.setattr(store, 'has_active_project',
|
||||
lambda: any(folder.glob('local-resource-*.json')) or original())
|
||||
result = incident(case)
|
||||
assert result['retry_error']['code'] == 'active_project_exists'
|
||||
path, = folder.glob('local-resource-*.json')
|
||||
assert json.loads(path.read_bytes())['never_acquired'] is True
|
||||
assert RunJournal(root).batch_summary(run_id)['resource_state'] == 'released'
|
||||
assert case['calls'] == ['OLD-OK', 'OLD-BAD']
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != 'nt', reason='Windows desktop lifetime')
|
||||
def test_local_retry_isolation_cannot_borrow_the_original_batch_release(
|
||||
confirmed_incident_batch, monkeypatch):
|
||||
import sys
|
||||
from dx_productivity.trial_task_center import batch as native_batch
|
||||
from dx_productivity.trial_task_center.batch_runtime import BatchCadRuntime
|
||||
from dx_productivity.trial_task_center.isolated_desktop import _Win32Api, build_startup_info
|
||||
from dx_productivity.trial_task_center.task_queue import _local_resource_path
|
||||
|
||||
case, held = confirmed_incident_batch
|
||||
held['value'] = False
|
||||
service, task_id, run_id, root = (case[key] for key in ('service', 'task_id', 'run_id', 'root'))
|
||||
manifest = json.loads((root / 'batch-runs' / run_id / 'manifest.json').read_bytes())
|
||||
_update_json(root / 'task-queues' / (run_id + '.json'), manifest_digest=manifest['manifest_digest'])
|
||||
with BatchCadRuntime(root, 'task_queue') as main:
|
||||
main.bind_logs(service._logging, (task_id,))
|
||||
main._ensure_desktop()
|
||||
batch_resources.write_record(root / _local_resource_path(run_id, main.session_id),
|
||||
{'version': 1, 'session_id': main.session_id, 'queue_id': run_id,
|
||||
'manifest_digest': manifest['manifest_digest'], 'task_ids': [task_id],
|
||||
'plan_hashes': manifest['plan_hashes'], 'never_acquired': False})
|
||||
assert main.record['state'] == 'released'
|
||||
execute_batch = native_batch.execute_batch
|
||||
external = None
|
||||
|
||||
def execute_on_retained_desktop(*args, runtime, **kwargs):
|
||||
nonlocal external
|
||||
desktop = runtime._ensure_desktop()
|
||||
external = _Win32Api().create_process((sys.executable, '-u', '-c',
|
||||
'import sys,time,win32service; '
|
||||
'desktop=win32service.OpenDesktop(sys.argv[1],0,False,0x10000000); '
|
||||
'desktop.SetThreadDesktop(); print("ready",flush=True); time.sleep(30)', desktop.name),
|
||||
build_startup_info(desktop.name).lpDesktop, None, None,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
assert external.stdout.readline() == b'ready\r\n'
|
||||
return execute_batch(*args, runtime=runtime, **kwargs)
|
||||
|
||||
monkeypatch.setattr(native_batch, 'execute_batch', execute_on_retained_desktop)
|
||||
try:
|
||||
incident(case)
|
||||
summary = RunJournal(root).batch_summary(run_id)
|
||||
assert summary['execution_status'] == 'completed'
|
||||
assert summary['status'] == 'paused' and summary['resource_state'] == 'isolated'
|
||||
assert {row['state'] for row in summary['resource']['generations']} == {'released', 'isolated'}
|
||||
assert external.poll() is None
|
||||
assert case['calls'] == ['OLD-OK', 'OLD-BAD', 'OLD-BAD']
|
||||
finally:
|
||||
if external is not None:
|
||||
external.close()
|
||||
assert batch_resources.cleanup_pending_resources(root) == ()
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != 'nt', reason='Windows supervisor launch')
|
||||
@pytest.mark.parametrize('link_writable', [True, False])
|
||||
def test_incident_supervisor_launch_requires_its_durable_request_link(
|
||||
confirmed_incident_batch, monkeypatch, link_writable):
|
||||
from dx_productivity.trial_task_center import batch_supervisor
|
||||
from dx_productivity.trial_task_center.isolated_desktop import _Win32Api
|
||||
|
||||
case, held = confirmed_incident_batch
|
||||
held['value'] = False
|
||||
service, task_id, run_id, root = (case[key] for key in ('service', 'task_id', 'run_id', 'root'))
|
||||
folder = root / 'batch-runs' / run_id
|
||||
manifest = json.loads((folder / 'manifest.json').read_bytes())
|
||||
_update_json(root / 'task-queues' / (run_id + '.json'), manifest_digest=manifest['manifest_digest'])
|
||||
execute = service.execute_quick_run_queue
|
||||
atomic_write = batch_resources.write_record
|
||||
launches = []
|
||||
|
||||
class FatalExit(BaseException):
|
||||
pass
|
||||
|
||||
def supervised_retry(*args, **kwargs):
|
||||
with monkeypatch.context() as mode:
|
||||
mode.setattr(service, '_supervised', True)
|
||||
return execute(*args, **kwargs)
|
||||
|
||||
def write_record(path, value):
|
||||
if not link_writable and Path(path).name.startswith('incident-resource-'):
|
||||
raise OSError('fixture cannot write incident link')
|
||||
return atomic_write(path, value)
|
||||
|
||||
def interrupt_at_create_process(*args, **kwargs):
|
||||
assert link_writable, 'worker launch must wait for durable incident binding'
|
||||
batch_id = service._last_supervisor_batch_id
|
||||
directory = root / 'batch-resources' / batch_id
|
||||
raw = (directory / 'request.json').read_bytes()
|
||||
supervisor = json.loads((directory / 'supervisor.json').read_bytes())
|
||||
link = json.loads((folder / f'incident-resource-{batch_id}.json').read_bytes())
|
||||
assert link == {'manifest_digest': manifest['manifest_digest'], 'task_id': task_id,
|
||||
'request_sha256': hashlib.sha256(raw).hexdigest()}
|
||||
assert supervisor['state'] == 'starting' and supervisor['process'] is None
|
||||
launches.append(batch_id)
|
||||
raise FatalExit('interrupted at native launch boundary')
|
||||
|
||||
monkeypatch.setattr(service, 'execute_quick_run_queue', supervised_retry)
|
||||
monkeypatch.setattr(batch_resources, 'write_record', write_record)
|
||||
monkeypatch.setattr(_Win32Api, 'create_process', interrupt_at_create_process)
|
||||
if link_writable:
|
||||
with pytest.raises(FatalExit):
|
||||
incident(case)
|
||||
execution_runs.recover_batch_receipts(service, root)
|
||||
summary = RunJournal(root).batch_summary(run_id)
|
||||
assert len(launches) == 1 and summary['resource_batch_ids'] == launches
|
||||
assert summary['status'] == 'interrupted' and summary['resource_state'] == 'unknown'
|
||||
else:
|
||||
result = incident(case)
|
||||
assert result['retry_error']['code'] == 'incident_resource_link_unavailable'
|
||||
assert not launches and not batch_supervisor.pending_supervisors(root)
|
||||
assert case['calls'] == ['OLD-OK', 'OLD-BAD']
|
||||
@@ -120,6 +120,10 @@ def test_inspect_restores_a_determined_resource_pause_only_from_its_original_bat
|
||||
batch_resources.write_record(directory / 'supervisor.json', dict(binding,
|
||||
operation='execute_task_queue', task_ids=ids, state='finished', process=identity,
|
||||
parent_process=identity, request_sha256=request_digest))
|
||||
batch_resources.write_record(directory / 'session.json', dict(version=1, session_id=batch_id,
|
||||
kind='task_queue', generation=1, desktop='dx-' + batch_id, state='released', processes=[],
|
||||
cad_pid=None, cad_guid=None, checkpoints={}, retries={}, timings=[], release_proof={
|
||||
'generation': 1, 'desktop_released': True, 'processes_exited': True}))
|
||||
paused = TaskQueueResult(token, tuple(TaskQueueEntry(item, row['state'])
|
||||
for item, row in state['entries'].items()), True, ids[0])
|
||||
batch_resources.write_record(directory / 'result.json', dict(binding, generation=1, sequence=1, type='result',
|
||||
@@ -166,7 +170,7 @@ def test_shared_safe_primary_failure_can_hold_remaining_commands_on_resume(proje
|
||||
|
||||
|
||||
@pytest.mark.parametrize('isolated', [True, False])
|
||||
def test_released_isolated_project_does_not_block_resume_of_other_projects(project_service, isolated):
|
||||
def test_released_projects_require_a_verified_result_to_resume_other_projects(project_service, isolated):
|
||||
from dx_productivity.dsh.run_journal import resume_preflight
|
||||
service, _, data, ids, hashes = project_service
|
||||
journal = RunJournal(data)
|
||||
@@ -181,13 +185,21 @@ def test_released_isolated_project_does_not_block_resume_of_other_projects(proje
|
||||
path.write_text(json.dumps({'version': 1, 'task_ids': ids, 'plan_hashes': hashes,
|
||||
'phase': 'primary' if isolated else 'problems', 'entries': entries}))
|
||||
result = journal.inspect(service, 'd' * 32)
|
||||
assert result['queue_available'] and result['resume_ready'], result['blockers']
|
||||
assert result['queue_available']
|
||||
assert result['remaining_task_ids'] == (ids[1:] if isolated else ids)
|
||||
assert result['isolated_task_ids'] == ([ids[0]] if isolated else [])
|
||||
assert result['tasks'][0]['interrupted'] == isolated
|
||||
assert result['tasks'][0]['interrupted'] is isolated
|
||||
if isolated:
|
||||
assert not result['resume_ready'] and 'interrupted' in result['blockers']
|
||||
assert not result['cad_execution_started']
|
||||
with pytest.raises(TaskCenterError) as caught:
|
||||
resume_preflight(service, result)
|
||||
assert caught.value.code == 'run_blocked'
|
||||
return
|
||||
assert result['resume_ready'], result['blockers']
|
||||
report = resume_preflight(service, result)
|
||||
assert report['ready']
|
||||
assert report['tasks'][0]['isolated'] == isolated
|
||||
assert report['tasks'][0]['isolated'] is False
|
||||
|
||||
|
||||
def test_unpaused_blocked_project_is_not_a_completed_run(project_service):
|
||||
|
||||
Reference in new issue
Block a user