[test/fix] prevent FirefoxHelper from silently failing to start

This was breaking some tests without any obvious error message and you should fail as early as possible to make debugging easier.

Closes #17260390

authorLaurent Peuch <cortex@worlddomination.be>
changesetda416fb21657
branchdefault
phasepublic
hiddenno
parent revision#053329493511 [doc] document debug toolbar
child revision#fce106b9977d [test/fix] tempfile is non portable linux command and is useless here
files modified by this revision
cubicweb/devtools/qunit.py
# HG changeset patch
# User Laurent Peuch <cortex@worlddomination.be>
# Date 1576598183 -3600
# Tue Dec 17 16:56:23 2019 +0100
# Node ID da416fb216570640d022a8cafb826ed4984438c4
# Parent 053329493511583c65824dca033f32402e1d79f1
[test/fix] prevent FirefoxHelper from silently failing to start

This was breaking some tests without any obvious error message and you should
fail as early as possible to make debugging easier.

Closes #17260390

diff --git a/cubicweb/devtools/qunit.py b/cubicweb/devtools/qunit.py
@@ -14,10 +14,11 @@
1  # details.
2  #
3  # You should have received a copy of the GNU Lesser General Public License along
4  # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5  import os, os.path as osp
6 +import time
7  import errno
8  import shutil
9  from queue import Queue, Empty
10  from tempfile import mkdtemp, TemporaryDirectory
11  from subprocess import Popen, PIPE, STDOUT
@@ -77,12 +78,22 @@
12          cmd = self.firefox_cmd + ['-silent', '--profile', self._profile_dir,
13                                    '-url', self._url]
14          with open(self.log_file, 'wb') as fout:
15              self._process = Popen(cmd, stdout=fout, stderr=STDOUT)
16 
17 +        # check that the process has correctly started
18 +        time.sleep(1)
19 +        if self._process.poll() is not None:
20 +            with open(self.log_file, 'r') as f:
21 +                log = f.read()
22 +
23 +            raise Exception("Error: failed to start firefox subprocess using the command "
24 +                            "'%s' with the return code '%s' and the output:\n\n%s" %
25 +                            (' '.join(cmd), self._process.poll(), log))
26 +
27      def stop(self):
28 -        if self._process is not None:
29 +        if self._process is not None and self._process.poll() is None:
30              assert self._process.returncode is None,  self._process.returncode
31              self._process.terminate()
32              self._process.wait()
33              self._process = None
34