fix: address defects found in frozen native acceptance
This commit is contained in:
1 parent
b86e4e315a
commit
42d0cebc54
15 files changed
+808
-50
No files matched your search
@@ -221,6 +221,54 @@ def test_export_does_not_adopt_unrelated_existing_native_owner(project, tmp_path
|
||||
assert len(started) == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize('remains_alive,database_busy', [(False, False), (True, False), (False, True)])
|
||||
def test_export_reobserves_access_denied_child_before_deciding_release(
|
||||
project, tmp_path, monkeypatch, remains_alive, database_busy):
|
||||
import json
|
||||
import pywintypes
|
||||
import win32api
|
||||
from cbb_refresh_verify import native_engineering_identity as identity
|
||||
source, _ = project
|
||||
root = tmp_path/'exports'; root.mkdir()
|
||||
launched, seen = [], {}
|
||||
class Finished:
|
||||
returncode = 0
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.pid = 980000+len(launched)*2
|
||||
launched.append(self)
|
||||
def poll(self): return 0
|
||||
def kill(self): pytest.fail('native owner must not be killed')
|
||||
def snapshot():
|
||||
if not launched: return []
|
||||
pid = launched[-1].pid
|
||||
seen[pid] = seen.get(pid, 0)+1
|
||||
if seen[pid] == 1 or remains_alive:
|
||||
return [{'pid': pid+1, 'parent': pid, 'name': 'conhost.exe',
|
||||
'command': '', 'executable': '', 'created': 'creation-identity'}]
|
||||
return []
|
||||
def denied(*args): raise pywintypes.error(5, 'OpenProcess', 'Access is denied')
|
||||
ticks = iter(i/100 for i in range(1000))
|
||||
monkeypatch.setattr(identity.time, 'monotonic', lambda: next(ticks))
|
||||
monkeypatch.setattr(identity.time, 'sleep', lambda _: None)
|
||||
monkeypatch.setattr(identity.subprocess, 'Popen', Finished)
|
||||
monkeypatch.setattr(identity, '_process_snapshot', snapshot)
|
||||
monkeypatch.setattr(identity, '_database_released', lambda _: not launched or not database_busy)
|
||||
monkeypatch.setattr(identity, 'validate_export_output', lambda *_: None)
|
||||
monkeypatch.setattr(identity, '_retained_exports', [])
|
||||
monkeypatch.setattr(win32api, 'OpenProcess', denied)
|
||||
result = identity._run_exports(source, root, tmp_path, .045)
|
||||
expected = not remains_alive and not database_busy
|
||||
assert result['success'] is expected
|
||||
assert result['safe_to_continue'] is expected
|
||||
record = json.loads((root/'ascii-process.json').read_text('utf-8'))
|
||||
assert record['process_identities'][0]['pid'] == launched[0].pid+1
|
||||
assert record['process_observation_errors'][str(launched[0].pid+1)]['winerror'] == 5
|
||||
if expected:
|
||||
assert len(launched) == 3 and not identity._retained_exports
|
||||
else:
|
||||
assert 'TIMEOUT' in result['detail'] and identity._retained_exports
|
||||
|
||||
|
||||
def test_export_spawn_failure_does_not_manufacture_native_ownership(project, tmp_path, monkeypatch):
|
||||
import cbb_refresh_verify.native_engineering_identity as identity
|
||||
source, _ = project
|
||||
|
||||
Reference in new issue
Block a user