fix: close owner probe cleanly when its request disappears
This commit is contained in:
1 parent
f4f5e939eb
commit
3223889dc7
2 files changed
+39
-1
No files matched your search
@@ -61,7 +61,12 @@ def owner_probe_main(job):
|
||||
import pythoncom
|
||||
import win32com.client
|
||||
job = Path(job)
|
||||
request = json.loads(job.read_text('utf-8'))
|
||||
try:
|
||||
request = json.loads(job.read_text('utf-8'))
|
||||
except (OSError, ValueError):
|
||||
return 1
|
||||
if not isinstance(request, dict):
|
||||
return 1
|
||||
full_snapshot = request == {'snapshot_version': 1} and type(request.get('snapshot_version')) is int
|
||||
names = request.get('names')
|
||||
if not full_snapshot:
|
||||
@@ -84,5 +89,8 @@ def owner_probe_main(job):
|
||||
response = {'snapshot_version': 1} if full_snapshot else {'names': names}
|
||||
job.with_name('result.json').write_text(json.dumps({**response, 'owners': rows}), encoding='utf-8')
|
||||
return 0
|
||||
except OSError:
|
||||
# The supervisor may remove its temporary request while this helper exits.
|
||||
return 1
|
||||
finally:
|
||||
pythoncom.CoUninitialize()
|
||||
@@ -90,3 +90,33 @@ def test_full_snapshot_helper_does_not_filter_unknown_descendants(tmp_path, monk
|
||||
assert len(queries) == 1 and 'WHERE' not in queries[0]
|
||||
row = json.loads(job.with_name('result.json').read_text('utf-8'))['owners'][0]
|
||||
assert row['name'] == 'custom-native-child.exe' and row['created'] == 'creation-time'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('contents', [None, b'broken-json', b'[]', b'\xff'])
|
||||
def test_readonly_helper_quietly_rejects_unavailable_request(tmp_path, contents):
|
||||
from cbb_refresh_verify.application import main
|
||||
|
||||
request = tmp_path/'request.json'
|
||||
if contents is not None:
|
||||
request.write_bytes(contents)
|
||||
assert main(['--owner-probe', str(request)]) == 1
|
||||
assert not request.with_name('result.json').exists()
|
||||
|
||||
|
||||
def test_readonly_helper_quietly_exits_when_supervisor_removes_probe(tmp_path, monkeypatch):
|
||||
from cbb_refresh_verify.owner_probe import owner_probe_main
|
||||
from types import SimpleNamespace
|
||||
import win32com.client
|
||||
|
||||
probe = tmp_path/'probe'
|
||||
probe.mkdir()
|
||||
request = probe/'request.json'
|
||||
request.write_text('{"names":["ExpeditionPCB.exe"]}', encoding='utf-8')
|
||||
|
||||
def enumerate_then_clean(_):
|
||||
request.unlink()
|
||||
probe.rmdir()
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(win32com.client, 'GetObject', lambda _: SimpleNamespace(ExecQuery=enumerate_then_clean))
|
||||
assert owner_probe_main(request) == 1
|
||||
Reference in new issue
Block a user