fix: release private desktop on worker launch failure
This commit is contained in:
1 parent
39985f7cfd
commit
311d0dd9a4
4 files changed
+137
-19
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def test_constructor_releases_private_desktop_when_process_launch_fails(monkeypatch):
|
||||
import cbb_refresh_verify.desktop_worker as module
|
||||
|
||||
class Handle:
|
||||
def __init__(self):
|
||||
self.closed = False
|
||||
|
||||
def Close(self):
|
||||
self.closed = True
|
||||
|
||||
def CloseDesktop(self):
|
||||
self.closed = True
|
||||
|
||||
desktop = Handle()
|
||||
job = Handle()
|
||||
|
||||
monkeypatch.setattr(module.win32service, 'CreateDesktop', lambda *args: desktop)
|
||||
monkeypatch.setattr(module.win32job, 'CreateJobObject', lambda *args: job)
|
||||
monkeypatch.setattr(module.win32process, 'STARTUPINFO', lambda: type('Startup', (), {})())
|
||||
monkeypatch.setattr(module.win32process, 'CreateProcess',
|
||||
lambda *args: (_ for _ in ()).throw(RuntimeError('launch failed')))
|
||||
|
||||
with pytest.raises(RuntimeError, match='launch failed'):
|
||||
module.DesktopWorker(['worker.exe'], 'PrivateDesk')
|
||||
|
||||
assert desktop.closed is True
|
||||
assert job.closed is True
|
||||
|
||||
|
||||
def test_library_flag_loads_ui_dependencies_before_creating_private_desktop(monkeypatch, tmp_path):
|
||||
import builtins
|
||||
import win32service
|
||||
import cbb_refresh_verify.mentor_adapter as module
|
||||
|
||||
created = []
|
||||
original_import = builtins.__import__
|
||||
executable = tmp_path / 'LibraryManager.exe'
|
||||
executable.touch()
|
||||
|
||||
def deny_pywinauto(name, *args, **kwargs):
|
||||
if name == 'pywinauto' or name.startswith('pywinauto.'):
|
||||
raise ImportError('pywinauto unavailable')
|
||||
return original_import(name, *args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(builtins, '__import__', deny_pywinauto)
|
||||
monkeypatch.setattr(module, 'library_manager_path', lambda: executable)
|
||||
monkeypatch.setattr(win32service, 'CreateDesktop',
|
||||
lambda *args: created.append(args))
|
||||
|
||||
with pytest.raises(ImportError, match='pywinauto unavailable'):
|
||||
module.read_library_flag('library.lmc', 'Block')
|
||||
|
||||
assert created == []
|
||||
Reference in new issue
Block a user