Diff
Modified: trunk/Tools/ChangeLog (88670 => 88671)
--- trunk/Tools/ChangeLog 2011-06-13 19:12:04 UTC (rev 88670)
+++ trunk/Tools/ChangeLog 2011-06-13 19:15:27 UTC (rev 88671)
@@ -1,3 +1,21 @@
+2011-06-13 Dirk Pranke <[email protected]>
+
+ Reviewed by Tony Chang.
+
+ webkitpy: add integration tests for new-run-webkit-httpd, stop calling shut_down_http_server
+ https://bugs.webkit.org/show_bug.cgi?id=62251
+
+ shut_down_http_server() was a total hack that was only used by
+ new-run-webkit-httpd, so I've moved the code there and switched
+ to using executive.kill_process() for the common case. The
+ method itself will be removed in the patch on bug 59993.
+
+ * Scripts/new-run-webkit-httpd:
+ * Scripts/webkitpy/layout_tests/port/apache_http_server.py:
+ * Scripts/webkitpy/layout_tests/port/http_server.py:
+ * Scripts/webkitpy/layout_tests/port/http_server_integrationtest.py: Added.
+ * Scripts/webkitpy/layout_tests/port/websocket_server.py:
+
2011-06-13 Tony Chang <[email protected]>
Reviewed by Dimitri Glazkov.
Modified: trunk/Tools/Scripts/new-run-webkit-httpd (88670 => 88671)
--- trunk/Tools/Scripts/new-run-webkit-httpd 2011-06-13 19:12:04 UTC (rev 88670)
+++ trunk/Tools/Scripts/new-run-webkit-httpd 2011-06-13 19:15:27 UTC (rev 88671)
@@ -70,9 +70,13 @@
if options.server == 'start':
httpd.start()
else:
- httpd.stop(force=True)
+ # FIXME: We use _shut_down_http_server() instead of stop_http_server()
+ # because stop() only works if start() was called previously in the
+ # same process. _shut_down() is too coarse and may kill unrelated
+ # web servers, so this is a hack. We should change the interface so we
+ # can rely on pid files or something.
+ port_obj._shut_down_http_server(None)
-
def main():
option_parser = optparse.OptionParser()
option_parser.add_option('-k', '--server',
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/apache_http_server.py (88670 => 88671)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/apache_http_server.py 2011-06-13 19:12:04 UTC (rev 88670)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/apache_http_server.py 2011-06-13 19:15:27 UTC (rev 88671)
@@ -227,7 +227,9 @@
"""Stops the apache http server."""
_log.debug("Shutting down any running http servers")
httpd_pid = None
- if os.path.exists(self._pid_file):
+ if self._httpd_proc:
+ httpd_pid = self._httpd_proc.pid
+ elif os.path.exists(self._pid_file):
httpd_pid = int(open(self._pid_file).readline())
- # FIXME: We shouldn't be calling a protected method of _port_obj!
- self._port_obj._shut_down_http_server(httpd_pid)
+ if httpd_pid:
+ self._executive.kill_process(httpd_pid)
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server.py (88670 => 88671)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server.py 2011-06-13 19:12:04 UTC (rev 88670)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server.py 2011-06-13 19:15:27 UTC (rev 88671)
@@ -226,14 +226,14 @@
# TODO(deanm): Find a nicer way to shutdown cleanly. Our log files are
# probably not being flushed, etc... why doesn't our python have os.kill ?
- def stop(self, force=False):
- if not force and not self.is_running():
+ def stop(self):
+ if not self.is_running():
return
httpd_pid = None
if self._process:
httpd_pid = self._process.pid
- self._port_obj._shut_down_http_server(httpd_pid)
+ self._executive.kill_process(httpd_pid)
if self._process:
# wait() is not threadsafe and can throw OSError due to:
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_base.py (88670 => 88671)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_base.py 2011-06-13 19:12:04 UTC (rev 88670)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_base.py 2011-06-13 19:15:27 UTC (rev 88671)
@@ -43,6 +43,7 @@
def __init__(self, port_obj):
self._port_obj = port_obj
+ self._executive = port_obj._executive
def wait_for_action(self, action):
"""Repeat the action for 20 seconds or until it succeeds. Returns
Added: trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_integrationtest.py (0 => 88671)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_integrationtest.py (rev 0)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_integrationtest.py 2011-06-13 19:15:27 UTC (rev 88671)
@@ -0,0 +1,126 @@
+# Copyright (C) 2011 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Integration testing for the new-run-webkit-httpd script"""
+
+import errno
+import os
+import socket
+import subprocess
+import sys
+import tempfile
+import unittest
+
+from webkitpy.layout_tests.port import port_testcase
+
+
+class NewRunWebKitHTTPdTest(unittest.TestCase):
+ """Tests that new-run-webkit-httpd must pass."""
+ HTTP_PORTS = (8000, 8080, 8443)
+
+ def assert_servers_are_down(self, host, ports):
+ for port in ports:
+ try:
+ test_socket = socket.socket()
+ test_socket.connect((host, port))
+ self.fail()
+ except IOError, e:
+ self.assertTrue(e.errno in (errno.ECONNREFUSED, errno.ECONNRESET))
+ finally:
+ test_socket.close()
+
+ def assert_servers_are_up(self, host, ports):
+ for port in ports:
+ try:
+ test_socket = socket.socket()
+ test_socket.connect((host, port))
+ except IOError, e:
+ self.fail('failed to connect to %s:%d' % (host, port))
+ finally:
+ test_socket.close()
+
+ def run_script(self, args):
+ script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+ script_path = os.path.join(script_dir, 'new-run-webkit-httpd')
+ return subprocess.call([sys.executable, script_path] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ def integration_test_http_server__normal(self):
+ self.assert_servers_are_down('localhost', self.HTTP_PORTS)
+ self.assertEquals(self.run_script(['--server', 'start']), 0)
+ self.assert_servers_are_up('localhost', self.HTTP_PORTS)
+ self.assertEquals(self.run_script(['--server', 'stop']), 0)
+ self.assert_servers_are_down('localhost', self.HTTP_PORTS)
+
+ def integration_test_http_server__fails(self):
+ # Test that if a port isn't available, the call fails.
+ for port_number in self.HTTP_PORTS:
+ test_socket = socket.socket()
+ try:
+ try:
+ test_socket.bind(('localhost', port_number))
+ except socket.error, e:
+ if e.errno in (errno.EADDRINUSE, errno.EALREADY):
+ self.fail('could not bind to port %d: %s' % (port_number, str(e)))
+ raise
+ self.assertEquals(self.run_script(['--server', 'start']), 1)
+ finally:
+ self.run_script(['--server', 'stop'])
+ test_socket.close()
+
+ # Test that calling start() twice fails.
+ try:
+ self.assertEquals(self.run_script(['--server', 'start']), 0)
+ self.assertEquals(self.run_script(['--server', 'start']), 1)
+ finally:
+ self.run_script(['--server', 'stop'])
+
+ # Test that calling stop() twice is harmless.
+ self.assertEquals(self.run_script(['--server', 'stop']), 0)
+
+ def maybe_make_dir(self, *comps):
+ try:
+ os.makedirs(os.path.join(*comps))
+ except OSError, e:
+ if e.errno != errno.EEXIST:
+ raise
+
+ def integration_test_http_server_port_and_root(self):
+ tmpdir = tempfile.mkdtemp(prefix='webkitpytest')
+ self.maybe_make_dir(tmpdir, 'http', 'tests')
+ self.maybe_make_dir(tmpdir, 'fast', 'js', 'resources')
+ self.maybe_make_dir(tmpdir, 'media')
+
+ self.assert_servers_are_down('localhost', [18000])
+ self.assertEquals(self.run_script(['--server', 'start', '--port=18000', '--root', tmpdir]), 0)
+ self.assert_servers_are_up('localhost', [18000])
+ self.assertEquals(self.run_script(['--server', 'stop']), 0)
+ self.assert_servers_are_down('localhost', [18000])
+
+
+if __name__ == '__main__':
+ port_testcase.main()
Property changes on: trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_integrationtest.py
___________________________________________________________________
Added: svn:executable
Added: svn:eol-style
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/port_testcase.py (88670 => 88671)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/port_testcase.py 2011-06-13 19:12:04 UTC (rev 88670)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/port_testcase.py 2011-06-13 19:15:27 UTC (rev 88671)
@@ -48,10 +48,9 @@
class PortTestCase(unittest.TestCase):
"""Tests that all Port implementations must pass."""
+ HTTP_PORTS = (8000, 8080, 8443)
+ WEBSOCKET_PORTS = (8880,)
- HTTP_PORTS = [8000, 8080, 8443]
- WEBSOCKET_PORTS = [8880]
-
def port_maker(self, platform):
"""Override to return the class object of the port to be tested,
or None if a valid port object cannot be constructed on the specified
@@ -92,23 +91,23 @@
def assert_servers_are_down(self, host, ports):
for port in ports:
try:
- s = socket.socket()
- s.connect((host, port))
+ test_socket = socket.socket()
+ test_socket.connect((host, port))
self.fail()
except IOError, e:
self.assertTrue(e.errno in (errno.ECONNREFUSED, errno.ECONNRESET))
finally:
- s.close()
+ test_socket.close()
def assert_servers_are_up(self, host, ports):
for port in ports:
try:
- s = socket.socket()
- s.connect((host, port))
+ test_socket = socket.socket()
+ test_socket.connect((host, port))
except IOError, e:
self.fail('failed to connect to %s:%d' % (host, port))
finally:
- s.close()
+ test_socket.close()
def integration_test_http_lock(self):
port = self.make_port()
@@ -137,7 +136,6 @@
port = self.make_port()
if not port:
return
-
self.assert_servers_are_down('localhost', self.HTTP_PORTS)
port.start_http_server()
self.assert_servers_are_up('localhost', self.HTTP_PORTS)
@@ -148,13 +146,12 @@
port = self.make_port()
if not port:
return
-
# Test that if a port isn't available, the call fails.
for port_number in self.HTTP_PORTS:
- s = socket.socket()
+ test_socket = socket.socket()
try:
try:
- s.bind(('localhost', port_number))
+ test_socket.bind(('localhost', port_number))
except socket.error, e:
if e.errno in (errno.EADDRINUSE, errno.EALREADY):
self.fail('could not bind to port %d' % port_number)
@@ -166,7 +163,7 @@
pass
finally:
port.stop_http_server()
- s.close()
+ test_socket.close()
# Test that calling start() twice fails.
try:
@@ -260,9 +257,9 @@
# Test that start() fails if a port isn't available.
for port_number in self.WEBSOCKET_PORTS:
- s = socket.socket()
+ test_socket = socket.socket()
try:
- s.bind(('localhost', port_number))
+ test_socket.bind(('localhost', port_number))
try:
port.start_websocket_server()
self.fail('should not have been able to start the server while bound to %d' % port_number)
@@ -270,7 +267,7 @@
pass
finally:
port.stop_websocket_server()
- s.close()
+ test_socket.close()
# Test that calling start() twice fails.
try:
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/websocket_server.py (88670 => 88671)
--- trunk/Tools/Scripts/webkitpy/layout_tests/port/websocket_server.py 2011-06-13 19:12:04 UTC (rev 88670)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/websocket_server.py 2011-06-13 19:15:27 UTC (rev 88671)
@@ -209,9 +209,7 @@
url = "" + '://127.0.0.1:%d/' % self._port
if not url_is_alive(url):
if self._process.returncode == None:
- # FIXME: We should use a non-static Executive for easier
- # testing.
- Executive().kill_process(self._process.pid)
+ self._executive.kill_process(self._process.pid)
with codecs.open(output_log, "r", "utf-8") as fp:
for line in fp:
_log.error(line)
@@ -227,8 +225,8 @@
with codecs.open(self._pidfile, "w", "ascii") as file:
file.write("%d" % self._process.pid)
- def stop(self, force=False):
- if not force and not self.is_running():
+ def stop(self):
+ if not self.is_running():
return
pid = None
@@ -243,8 +241,7 @@
'Failed to find %s server pid.' % self._server_name)
_log.debug('Shutting down %s server %d.' % (self._server_name, pid))
- # FIXME: We should use a non-static Executive for easier testing.
- Executive().kill_process(pid)
+ self._executive.kill_process(pid)
if self._process:
# wait() is not threadsafe and can throw OSError due to: