tests: Don't wait for testprocess if it quits.
This commit is contained in:
parent
e944239ae8
commit
258855cf50
@ -90,6 +90,18 @@ class QuitPythonProcess(PythonProcess):
|
|||||||
return (sys.executable, ['-c', ';'.join(code)])
|
return (sys.executable, ['-c', ';'.join(code)])
|
||||||
|
|
||||||
|
|
||||||
|
class NoReadyPythonProcess(PythonProcess):
|
||||||
|
|
||||||
|
"""A testprocess which never emits 'ready' and quits."""
|
||||||
|
|
||||||
|
def _executable_args(self):
|
||||||
|
code = [
|
||||||
|
'import sys',
|
||||||
|
'sys.exit(0)',
|
||||||
|
]
|
||||||
|
return (sys.executable, ['-c', ';'.join(code)])
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def pyproc():
|
def pyproc():
|
||||||
proc = PythonProcess()
|
proc = PythonProcess()
|
||||||
@ -104,6 +116,20 @@ def quit_pyproc():
|
|||||||
proc.terminate()
|
proc.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.yield_fixture
|
||||||
|
def noready_pyproc():
|
||||||
|
proc = NoReadyPythonProcess()
|
||||||
|
yield proc
|
||||||
|
proc.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_ready_python_process(noready_pyproc):
|
||||||
|
"""When a process quits immediately, waiting for start should interrupt."""
|
||||||
|
with pytest.raises(testprocess.ProcessExited):
|
||||||
|
with stopwatch(max_ms=5000):
|
||||||
|
noready_pyproc.start()
|
||||||
|
|
||||||
|
|
||||||
def test_quitting_process(qtbot, quit_pyproc):
|
def test_quitting_process(qtbot, quit_pyproc):
|
||||||
with qtbot.waitSignal(quit_pyproc.proc.finished):
|
with qtbot.waitSignal(quit_pyproc.proc.finished):
|
||||||
quit_pyproc.start()
|
quit_pyproc.start()
|
||||||
|
@ -215,8 +215,21 @@ class Process(QObject):
|
|||||||
|
|
||||||
def start(self, args=None, *, env=None):
|
def start(self, args=None, *, env=None):
|
||||||
"""Start the process and wait until it started."""
|
"""Start the process and wait until it started."""
|
||||||
with self._wait_signal(self.ready, timeout=60000):
|
self._start(args, env=env)
|
||||||
self._start(args, env=env)
|
for _ in range(30):
|
||||||
|
with self._wait_signal(self.ready, timeout=1000,
|
||||||
|
raising=False) as blocker:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not self.is_running():
|
||||||
|
# _start ensures it actually started, but it might quit shortly
|
||||||
|
# afterwards
|
||||||
|
raise ProcessExited()
|
||||||
|
|
||||||
|
if blocker.signal_triggered:
|
||||||
|
return
|
||||||
|
|
||||||
|
raise WaitForTimeout("Timed out while waiting for process start.")
|
||||||
|
|
||||||
def _start(self, args, env):
|
def _start(self, args, env):
|
||||||
"""Actually start the process."""
|
"""Actually start the process."""
|
||||||
|
Loading…
Reference in New Issue
Block a user