BurnyCoder's picture
Publish resumable postponement before restoring the interrupted seed
f043c42 verified
Raw History Blame Contribute Delete
1.21 kB
"""Reproduce the Windows reader/writer collision observed on the live curves file."""
import json
import pytest
from novel_tokens import runtime
def test_local_postponement_does_not_consume_a_milestone(tmp_path, monkeypatch):
monkeypatch.setattr(runtime,"STORE",tmp_path)
runtime.check_postponed()
(tmp_path/"postpone.request").touch()
with pytest.raises(runtime.CampaignPostponed):
runtime.check_postponed()
assert not list(tmp_path.glob("*milestones/*.json"))
def test_atomic_writer_retries_sharing_violation(tmp_path, monkeypatch):
dest = tmp_path / "curves.json"
runtime.save_json(dest, {"step": 112})
replace = runtime.os.replace
attempts = []
def held_once(source, target):
attempts.append(target)
if len(attempts) == 1:
assert json.loads(dest.read_bytes()) == {"step": 112}
error = PermissionError("test reader still holds the destination")
error.winerror = 5
raise error
replace(source, target)
monkeypatch.setattr(runtime.os, "replace", held_once)
runtime.save_json(dest, {"step": 113})
assert len(attempts) == 2 and json.loads(dest.read_bytes()) == {"step": 113}