Skip to content

Commit f18e02b

Browse files
committed
Cover export preparation publication race
1 parent 6252f70 commit f18e02b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎tests/test_sav_sqlite.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,31 @@ def test_export_recovery_does_not_replace_newer_concurrent_destination(
283283
assert destination.read_bytes() == b"later successful export"
284284
assert backup.read_bytes() == b"original destination"
285285

286+
def test_export_publication_does_not_clobber_intervening_destination(
287+
tmp_path, monkeypatch,
288+
) -> None:
289+
staged = tmp_path / "staged.sav"
290+
destination = tmp_path / "destination.sav"
291+
backup = tmp_path / "destination.previous"
292+
staged.write_bytes(b"earlier staged export")
293+
real_link = sav_module.os.link
294+
295+
def publish_concurrently(source, target):
296+
destination.write_bytes(b"intervening successful export")
297+
return real_link(source, target)
298+
299+
monkeypatch.setattr(sav_module.os, "link", publish_concurrently)
300+
state = {}
301+
with pytest.raises(FileExistsError):
302+
sav_module._publish_staged_destination(
303+
staged=staged,
304+
destination=destination,
305+
backup=backup,
306+
state=state,
307+
)
308+
309+
assert destination.read_bytes() == b"intervening successful export"
310+
assert staged.read_bytes() == b"earlier staged export"
311+
assert sav_module._path_entry_exists(backup) is False
312+
assert state["published_identity"] is None
313+

0 commit comments

Comments
 (0)