<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212905] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212905">212905</a></dd>
<dt>Author</dt> <dd>clopez@igalia.com</dd>
<dt>Date</dt> <dd>2017-02-23 11:04:33 -0800 (Thu, 23 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Improve error message when the WPT server fails to start.
https://bugs.webkit.org/show_bug.cgi?id=168759

Reviewed by Ryosuke Niwa.

Check if the WPT server is running after 1 second, and if is not
print useful information for helping the user to debug the issue.

Using check_running_pid() to check if the process is still running
doesn't work. A process started via subprocess popen that has ended
will be in a zombie state until a call to wait/communicate/poll
is done, or until the object is deleted or garbage collected.

This adds also support for testing the behaviour of subprocess
poll() on the unit tests that use MockProcess.

A new test is added also for the battery of tests for the WPT
server.

* Scripts/webkitpy/common/system/executive_mock.py:
(MockProcess.__init__):
(MockProcess.wait):
(MockProcess.communicate):
(MockProcess.poll):
(MockExecutive.popen):
* Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py:
(WebPlatformTestServer.__init__):
(WebPlatformTestServer._prepare_config):
(WebPlatformTestServer._spawn_process):
* Scripts/webkitpy/layout_tests/servers/web_platform_test_server_unittest.py:
(TestWebPlatformTestServer.test_corrupted_subserver_files):
(TestWebPlatformTestServer):
(TestWebPlatformTestServer.test_server_fails_to_start_throws_exception):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpycommonsystemexecutive_mockpy">trunk/Tools/Scripts/webkitpy/common/system/executive_mock.py</a></li>
<li><a href="#trunkToolsScriptswebkitpylayout_testsserversweb_platform_test_serverpy">trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py</a></li>
<li><a href="#trunkToolsScriptswebkitpylayout_testsserversweb_platform_test_server_unittestpy">trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server_unittest.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (212904 => 212905)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-02-23 19:01:29 UTC (rev 212904)
+++ trunk/Tools/ChangeLog        2017-02-23 19:04:33 UTC (rev 212905)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2017-02-23  Carlos Alberto Lopez Perez  &lt;clopez@igalia.com&gt;
+
+        Improve error message when the WPT server fails to start.
+        https://bugs.webkit.org/show_bug.cgi?id=168759
+
+        Reviewed by Ryosuke Niwa.
+
+        Check if the WPT server is running after 1 second, and if is not
+        print useful information for helping the user to debug the issue.
+
+        Using check_running_pid() to check if the process is still running
+        doesn't work. A process started via subprocess popen that has ended
+        will be in a zombie state until a call to wait/communicate/poll
+        is done, or until the object is deleted or garbage collected.
+
+        This adds also support for testing the behaviour of subprocess
+        poll() on the unit tests that use MockProcess.
+
+        A new test is added also for the battery of tests for the WPT
+        server.
+
+        * Scripts/webkitpy/common/system/executive_mock.py:
+        (MockProcess.__init__):
+        (MockProcess.wait):
+        (MockProcess.communicate):
+        (MockProcess.poll):
+        (MockExecutive.popen):
+        * Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py:
+        (WebPlatformTestServer.__init__):
+        (WebPlatformTestServer._prepare_config):
+        (WebPlatformTestServer._spawn_process):
+        * Scripts/webkitpy/layout_tests/servers/web_platform_test_server_unittest.py:
+        (TestWebPlatformTestServer.test_corrupted_subserver_files):
+        (TestWebPlatformTestServer):
+        (TestWebPlatformTestServer.test_server_fails_to_start_throws_exception):
+
</ins><span class="cx"> 2017-02-23  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, temporarily disable DataInteractionTests in TestWebKitAPI.
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpycommonsystemexecutive_mockpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/common/system/executive_mock.py (212904 => 212905)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/common/system/executive_mock.py        2017-02-23 19:01:29 UTC (rev 212904)
+++ trunk/Tools/Scripts/webkitpy/common/system/executive_mock.py        2017-02-23 19:04:33 UTC (rev 212905)
</span><span class="lines">@@ -42,14 +42,22 @@
</span><span class="cx">         self.stderr = StringIO.StringIO(stderr)
</span><span class="cx">         self.stdin = StringIO.StringIO()
</span><span class="cx">         self.returncode = 0
</span><ins>+        self._is_running = False
</ins><span class="cx"> 
</span><span class="cx">     def wait(self):
</span><del>-        return
</del><ins>+        self._is_running = False
+        return self.returncode
</ins><span class="cx"> 
</span><span class="cx">     def communicate(self, input=None):
</span><ins>+        self._is_running = False
</ins><span class="cx">         return (self.stdout, self.stderr)
</span><span class="cx"> 
</span><ins>+    def poll(self):
+        if self._is_running:
+            return None
+        return self.returncode
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> # FIXME: This should be unified with MockExecutive2
</span><span class="cx"> class MockExecutive(object):
</span><span class="cx">     PIPE = &quot;MOCK PIPE&quot;
</span><span class="lines">@@ -146,6 +154,7 @@
</span><span class="cx">             _log.info(&quot;MOCK popen: %s%s%s&quot; % (args, cwd_string, env_string))
</span><span class="cx">         if not self._proc:
</span><span class="cx">             self._proc = MockProcess()
</span><ins>+        self._proc._is_running = True
</ins><span class="cx">         return self._proc
</span><span class="cx"> 
</span><span class="cx">     def run_in_parallel(self, commands):
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpylayout_testsserversweb_platform_test_serverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py (212904 => 212905)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py        2017-02-23 19:01:29 UTC (rev 212904)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py        2017-02-23 19:04:33 UTC (rev 212905)
</span><span class="lines">@@ -66,6 +66,7 @@
</span><span class="cx">         self._name = name
</span><span class="cx">         self._log_file_name = '%s_process_log.out.txt' % (self._name)
</span><span class="cx"> 
</span><ins>+        self._output_log_path = None
</ins><span class="cx">         self._wsout = None
</span><span class="cx">         self._process = None
</span><span class="cx">         self._pid_file = pidfile
</span><span class="lines">@@ -140,8 +141,8 @@
</span><span class="cx"> 
</span><span class="cx">     def _prepare_config(self):
</span><span class="cx">         if self._filesystem.exists(self._output_dir):
</span><del>-            output_log = self._filesystem.join(self._output_dir, self._log_file_name)
-            self._wsout = self._filesystem.open_text_file_for_writing(output_log)
</del><ins>+            self._output_log_path = self._filesystem.join(self._output_dir, self._log_file_name)
+            self._wsout = self._filesystem.open_text_file_for_writing(self._output_log_path)
</ins><span class="cx">         self._install_modules()
</span><span class="cx">         self._copy_webkit_test_files()
</span><span class="cx"> 
</span><span class="lines">@@ -157,6 +158,16 @@
</span><span class="cx">         # Wait a second for the server to actually start so that tests do not start until server is running.
</span><span class="cx">         time.sleep(1)
</span><span class="cx"> 
</span><ins>+        # The server is not running after 1 second, something went wrong.
+        if self._process.poll() is not None:
+            self._stop_running_server()
+            error_log = ('WPT Server process exited prematurely with status code %s\n' % self._process.returncode
+                         + 'The cmdline for running the WPT server was: %s\n' % self._start_cmd
+                         + 'The working dir was: %s\n' % self._doc_root_path)
+            if self._output_log_path is not None and self._filesystem.exists(self._output_log_path):
+                error_log += 'Check the logfile for the command at: %s\n' % self._output_log_path
+            raise http_server_base.ServerError(error_log)
+
</ins><span class="cx">         return self._process.pid
</span><span class="cx"> 
</span><span class="cx">     def _stop_running_subservers(self):
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpylayout_testsserversweb_platform_test_server_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server_unittest.py (212904 => 212905)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server_unittest.py        2017-02-23 19:01:29 UTC (rev 212904)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server_unittest.py        2017-02-23 19:04:33 UTC (rev 212905)
</span><span class="lines">@@ -97,3 +97,19 @@
</span><span class="cx">         server.start()
</span><span class="cx">         self.assertFalse(host.filesystem.exists(&quot;/mock/output_dir/wpttest_servers.json&quot;))
</span><span class="cx">         server.stop()
</span><ins>+
+    def test_server_fails_to_start_throws_exception(self):
+        host = MockHost()
+        options = optparse.Values()
+        options.ensure_value(&quot;results_directory&quot;, &quot;/mock/output_dir&quot;)
+        port = Port(host, &quot;test&quot;, options)
+        server = WebPlatformTestServer(port, &quot;wpttest&quot;, &quot;/mock/output_dir/pid.txt&quot;)
+        server._check_that_all_ports_are_available = lambda: True
+        server._is_server_running_on_all_ports = lambda: True
+        host.filesystem.write_text_file(&quot;/mock-checkout/LayoutTests/resources/testharness.js&quot;, &quot;0&quot;)
+        host.filesystem.write_text_file(&quot;/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/resources/testharness.js&quot;, &quot;0&quot;)
+
+        server.start()
+        server.stop()
+        server._process.poll = lambda: 1
+        self.assertRaises(ServerError, server.start)
</ins></span></pre>
</div>
</div>

</body>
</html>