test: cover shared retry budgets and supervisor process crashes
This commit is contained in:
1 parent
9837ca581b
commit
62f143fe9f
3 files changed
+165
No files matched your search
@@ -367,6 +367,69 @@ def test_native_rebuild_requires_strict_source_and_worker_proof(tmp_path):
|
||||
assert len(Desktop.created) == 2
|
||||
|
||||
|
||||
def test_mock_native_read_recovery_spends_same_project_worker_retry_budget(tmp_path, monkeypatch):
|
||||
"""Real durable proof/runtime logic; desktop, CAD and worker failure are fakes."""
|
||||
import hashlib
|
||||
from dx_productivity.trial_task_center.worker_monitor import WorkerMonitorError
|
||||
command, project = command_for(tmp_path)
|
||||
database = project.parent / 'database.dat'
|
||||
database.write_bytes(b'unchanged database')
|
||||
evidence = Path(command[3]) / 'native'
|
||||
evidence.mkdir()
|
||||
calls = []
|
||||
def fail_worker(*args, **kwargs):
|
||||
calls.append(1)
|
||||
raise WorkerMonitorError('prewrite failure after native recovery')
|
||||
runtime = worker_runtime(tmp_path, monkeypatch, fail_worker)
|
||||
with runtime:
|
||||
with runtime.native_scope(evidence) as scope:
|
||||
pass
|
||||
proof = {'version': 1, 'native_read_only': True, 'workers_closed': True,
|
||||
'binding': scope.identity, 'project_path': str(project.resolve()),
|
||||
'evidence_root': str(evidence.resolve()),
|
||||
'source_hashes': {str(path.resolve()): hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
for path in (project, database)}}
|
||||
(evidence / 'native-retry-proof.json').write_text(json.dumps(proof))
|
||||
assert runtime.recover_native_failure(project, evidence, 'read timeout')
|
||||
assert len(Desktop.created) == 2 and Desktop.created[0].released
|
||||
with pytest.raises(WorkerMonitorError, match='after native recovery'):
|
||||
runtime.run_worker(command, 5)
|
||||
assert calls == [1]
|
||||
assert len(Desktop.created) == 2
|
||||
assert not runtime.recover_native_failure(project, evidence, 'another read timeout')
|
||||
assert all(desktop.released for desktop in Desktop.created)
|
||||
assert runtime.record['retries'][str(project.resolve()).casefold()]['count'] == 1
|
||||
|
||||
|
||||
def test_mock_different_projects_each_get_one_retry_without_accumulating_budget(tmp_path, monkeypatch):
|
||||
"""Real per-project accounting; fake CAD/desktop and unchanged prewrite failures."""
|
||||
import subprocess
|
||||
from dx_productivity.trial_task_center.worker_monitor import WorkerMonitorError
|
||||
one, project_one = command_for(tmp_path)
|
||||
two, project_two = command_for(tmp_path, 'two')
|
||||
calls = {one[3]: 0, two[3]: 0}
|
||||
def monitor(command, *args, **kwargs):
|
||||
calls[command[3]] += 1
|
||||
if calls[command[3]] == 2:
|
||||
return subprocess.CompletedProcess(command, 0, '', '')
|
||||
raise WorkerMonitorError('unchanged prewrite failure')
|
||||
runtime = worker_runtime(tmp_path, monkeypatch, monitor)
|
||||
with runtime:
|
||||
runtime.run_worker(one, 5)
|
||||
assert len(Desktop.created) == 2
|
||||
runtime.run_worker(two, 5)
|
||||
assert len(Desktop.created) == 3 # Each project gets its own single rebuild.
|
||||
for command in (one, two):
|
||||
with pytest.raises(WorkerMonitorError, match='prewrite failure'):
|
||||
runtime.run_worker(command, 5)
|
||||
assert len(Desktop.created) == 3 # Success cannot replenish either budget.
|
||||
assert calls == {one[3]: 3, two[3]: 3}
|
||||
assert set(runtime.record['retries']) == {
|
||||
str(project_one.resolve()).casefold(), str(project_two.resolve()).casefold()}
|
||||
assert all(value['count'] == 1 for value in runtime.record['retries'].values())
|
||||
assert all(desktop.released for desktop in Desktop.created)
|
||||
|
||||
|
||||
def test_release_publication_failure_can_be_reconciled_without_replaying(tmp_path, monkeypatch):
|
||||
from dx_productivity.trial_task_center import batch_runtime
|
||||
runtime = batch_runtime.BatchCadRuntime(tmp_path, 'execution', desktop_factory=Desktop)
|
||||
|
||||
Reference in new issue
Block a user