Improve error message when the WPT server fails to start.
authorclopez@igalia.com <clopez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Feb 2017 19:04:33 +0000 (19:04 +0000)
committerclopez@igalia.com <clopez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Feb 2017 19:04:33 +0000 (19:04 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212905 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/system/executive_mock.py
Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py
Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server_unittest.py

index b478f8e..98b9eae 100644 (file)
@@ -1,3 +1,39 @@
+2017-02-23  Carlos Alberto Lopez Perez  <clopez@igalia.com>
+
+        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):
+
 2017-02-23  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Unreviewed, temporarily disable DataInteractionTests in TestWebKitAPI.
index c79a243..8bc43c6 100644 (file)
@@ -42,13 +42,21 @@ class MockProcess(object):
         self.stderr = StringIO.StringIO(stderr)
         self.stdin = StringIO.StringIO()
         self.returncode = 0
+        self._is_running = False
 
     def wait(self):
-        return
+        self._is_running = False
+        return self.returncode
 
     def communicate(self, input=None):
+        self._is_running = False
         return (self.stdout, self.stderr)
 
+    def poll(self):
+        if self._is_running:
+            return None
+        return self.returncode
+
 
 # FIXME: This should be unified with MockExecutive2
 class MockExecutive(object):
@@ -146,6 +154,7 @@ class MockExecutive(object):
             _log.info("MOCK popen: %s%s%s" % (args, cwd_string, env_string))
         if not self._proc:
             self._proc = MockProcess()
+        self._proc._is_running = True
         return self._proc
 
     def run_in_parallel(self, commands):
index 4dec0e9..a193d93 100755 (executable)
@@ -66,6 +66,7 @@ class WebPlatformTestServer(http_server_base.HttpServerBase):
         self._name = name
         self._log_file_name = '%s_process_log.out.txt' % (self._name)
 
+        self._output_log_path = None
         self._wsout = None
         self._process = None
         self._pid_file = pidfile
@@ -140,8 +141,8 @@ class WebPlatformTestServer(http_server_base.HttpServerBase):
 
     def _prepare_config(self):
         if self._filesystem.exists(self._output_dir):
-            output_log = self._filesystem.join(self._output_dir, self._log_file_name)
-            self._wsout = self._filesystem.open_text_file_for_writing(output_log)
+            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)
         self._install_modules()
         self._copy_webkit_test_files()
 
@@ -157,6 +158,16 @@ class WebPlatformTestServer(http_server_base.HttpServerBase):
         # Wait a second for the server to actually start so that tests do not start until server is running.
         time.sleep(1)
 
+        # 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)
+
         return self._process.pid
 
     def _stop_running_subservers(self):
index 2059fd7..896ceb1 100644 (file)
@@ -97,3 +97,19 @@ class TestWebPlatformTestServer(unittest.TestCase):
         server.start()
         self.assertFalse(host.filesystem.exists("/mock/output_dir/wpttest_servers.json"))
         server.stop()
+
+    def test_server_fails_to_start_throws_exception(self):
+        host = MockHost()
+        options = optparse.Values()
+        options.ensure_value("results_directory", "/mock/output_dir")
+        port = Port(host, "test", options)
+        server = WebPlatformTestServer(port, "wpttest", "/mock/output_dir/pid.txt")
+        server._check_that_all_ports_are_available = lambda: True
+        server._is_server_running_on_all_ports = lambda: True
+        host.filesystem.write_text_file("/mock-checkout/LayoutTests/resources/testharness.js", "0")
+        host.filesystem.write_text_file("/mock-checkout/LayoutTests/imported/w3c/web-platform-tests/resources/testharness.js", "0")
+
+        server.start()
+        server.stop()
+        server._process.poll = lambda: 1
+        self.assertRaises(ServerError, server.start)