Retry transient Windows sharing conflicts when publishing private CAD state
This commit is contained in:
1 parent
980198a987
commit
7610a0fd86
2 files changed
+54
-2
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from threading import Event
|
||||
from threading import Timer
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
@@ -10,6 +12,41 @@ from dx_productivity.trial_task_center import isolated_cad as runtime
|
||||
from dx_productivity.trial_task_center.worker_monitor import WorkerMonitorError
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != 'nt', reason='Windows state-file sharing semantics')
|
||||
def test_private_record_survives_a_reader_temporarily_denying_replacement(tmp_path):
|
||||
import win32con
|
||||
import win32file
|
||||
session = runtime.IsolatedCadSession(tmp_path)
|
||||
session._record(state='starting')
|
||||
held = win32file.CreateFile(str(tmp_path / 'private-desktop.json'), win32con.GENERIC_READ,
|
||||
win32con.FILE_SHARE_READ, None, win32con.OPEN_EXISTING, 0, None)
|
||||
reader_done = Timer(0.1, held.Close)
|
||||
reader_done.start()
|
||||
try:
|
||||
session._record(state='released', clean=True)
|
||||
finally:
|
||||
reader_done.join()
|
||||
current = json.loads((tmp_path / 'private-desktop.json').read_text())
|
||||
archived = json.loads((tmp_path / 'private-desktop-sessions' / (session.token + '.json')).read_text())
|
||||
assert current == archived and current['state'] == 'released' and current['clean']
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != 'nt', reason='Windows state-file sharing semantics')
|
||||
def test_private_record_reports_persistent_denial_and_keeps_previous_record(tmp_path):
|
||||
import win32con
|
||||
import win32file
|
||||
session = runtime.IsolatedCadSession(tmp_path)
|
||||
session._record(state='starting')
|
||||
held = win32file.CreateFile(str(tmp_path / 'private-desktop.json'), win32con.GENERIC_READ,
|
||||
win32con.FILE_SHARE_READ, None, win32con.OPEN_EXISTING, 0, None)
|
||||
try:
|
||||
with pytest.raises(PermissionError):
|
||||
session._record(state='released', clean=True)
|
||||
assert json.loads((tmp_path / 'private-desktop.json').read_text())['state'] == 'starting'
|
||||
finally:
|
||||
held.Close()
|
||||
|
||||
|
||||
def fake_desktop(monkeypatch, tmp_path, *, abort=None, quit_code=0, cad_exit_code=0):
|
||||
events = []
|
||||
cad = SimpleNamespace(pid=123, returncode=None)
|
||||
|
||||
Reference in new issue
Block a user