tests: Don't wait for testprocess if it quits.

This commit is contained in:
Florian Bruhin 2016-01-20 07:47:50 +01:00
parent e944239ae8
commit 258855cf50
2 changed files with 41 additions and 2 deletions

View File

@ -90,6 +90,18 @@ class QuitPythonProcess(PythonProcess):
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
def pyproc():
proc = PythonProcess()
@ -104,6 +116,20 @@ def quit_pyproc():
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):
with qtbot.waitSignal(quit_pyproc.proc.finished):
quit_pyproc.start()

View File

@ -215,8 +215,21 @@ class Process(QObject):
def start(self, args=None, *, env=None):
"""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):
"""Actually start the process."""