Changeset 85665 in webkit
- Timestamp:
- May 3, 2011 2:51:33 PM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r85659 r85665 1 2011-05-03 Dirk Pranke <dpranke@chromium.org> 2 3 Unreviewed, rolling out r85659. 4 http://trac.webkit.org/changeset/85659 5 https://bugs.webkit.org/show_bug.cgi?id=59977 6 7 restarting isn't working correctly 8 9 * Scripts/webkitpy/layout_tests/port/apache_http_server.py: 10 * Scripts/webkitpy/layout_tests/port/http_server.py: 11 * Scripts/webkitpy/layout_tests/port/http_server_base.py: 12 * Scripts/webkitpy/layout_tests/port/websocket_server.py: 13 1 14 2011-05-03 Dirk Pranke <dpranke@chromium.org> 2 15 -
trunk/Tools/Scripts/webkitpy/layout_tests/port/apache_http_server.py
r85659 r85665 198 198 # Note: Not thread safe: http://bugs.python.org/issue2320 199 199 _log.debug('Starting http server, cmd="%s"' % str(self._start_cmd)) 200 self._process = subprocess.Popen(self._start_cmd, stderr=subprocess.PIPE, shell=True) 201 err = self._process.stderr.read() 200 self._httpd_proc = subprocess.Popen(self._start_cmd, 201 stderr=subprocess.PIPE, 202 shell=True) 203 err = self._httpd_proc.stderr.read() 202 204 if len(err): 203 205 _log.debug(err) … … 207 209 def start(self): 208 210 """Starts the apache http server.""" 209 if self._process: 210 raise http_server_base.ServerError('httpd already running') 211 212 self.check_that_all_ports_are_available() 211 # Stop any currently running servers. 212 self.stop() 213 213 214 214 _log.debug("Starting apache http server") … … 222 222 _log.debug("Server successfully started") 223 223 else: 224 raise http_server_base.ServerError('Failed to start http server')224 raise Exception('Failed to start http server') 225 225 226 226 def stop(self): … … 228 228 _log.debug("Shutting down any running http servers") 229 229 httpd_pid = None 230 if self._process: 231 httpd_pid = self._process.pid 232 elif os.path.exists(self._pid_file): 230 if os.path.exists(self._pid_file): 233 231 httpd_pid = int(open(self._pid_file).readline()) 234 235 if not httpd_pid: 236 return 237 238 self._port_obj._executive.kill_process(httpd_pid) 239 240 if self._process: 241 self._process.wait() 242 self._process = None 243 if os.path.exists(self._pid_file): 244 os.remove(self._pid_file) 232 # FIXME: We shouldn't be calling a protected method of _port_obj! 233 self._port_obj._shut_down_http_server(httpd_pid) -
trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server.py
r85659 r85665 59 59 http_server_base.HttpServerBase.__init__(self, port_obj) 60 60 self._output_dir = output_dir 61 self._process = None 61 62 self._port = port 62 63 self._root = root … … 99 100 'sslcert': self._pem_file}]) 100 101 102 def is_running(self): 103 return self._process != None 104 101 105 def start(self): 102 106 if self.is_running(): 103 raise http_server_base.ServerError('Lighttpd already running')107 raise 'Lighttpd already running' 104 108 105 109 base_conf_file = self._port_obj.path_from_webkit_base('Tools', … … 113 117 114 118 # Remove old log files. We only need to keep the last ones. 115 # Don't worry too much if we can't remove the old ones. Sometimes 116 # they are locked by other processes but this clears eventually. 117 try: 118 self.remove_log_files(self._output_dir, "access.log-") 119 self.remove_log_files(self._output_dir, "error.log-") 120 except OSError, e: 121 _log.warning('Failed to remove old http server log files') 122 pass 119 self.remove_log_files(self._output_dir, "access.log-") 120 self.remove_log_files(self._output_dir, "error.log-") 123 121 124 122 # Write out the config … … 211 209 212 210 env = self._port_obj.setup_environ_for_server() 213 214 self.mappings = mappings215 self.check_that_all_ports_are_available()216 217 211 _log.debug('Starting http server, cmd="%s"' % str(start_cmd)) 218 212 # FIXME: Should use Executive.run_command 219 213 self._process = subprocess.Popen(start_cmd, env=env, stdin=subprocess.PIPE) 220 server_started = self.wait_for_action(self.is_server_running_on_all_ports) 214 215 # Wait for server to start. 216 self.mappings = mappings 217 server_started = self.wait_for_action( 218 self.is_server_running_on_all_ports) 219 220 # Our process terminated already 221 221 if not server_started or self._process.returncode != None: 222 raise http_server_base.ServerError('Failed to start httpd.')222 raise Exception('Failed to start httpd.') 223 223 224 224 _log.debug("Server successfully started") 225 225 226 # FIXME: It would be nice if we could shut the server down cleanly. 227 def stop(self): 228 if not self.is_running(): 226 # TODO(deanm): Find a nicer way to shutdown cleanly. Our log files are 227 # probably not being flushed, etc... why doesn't our python have os.kill ? 228 229 def stop(self, force=False): 230 if not force and not self.is_running(): 229 231 return 230 232 231 httpd_pid = self._process.pid 232 self._executive.kill_process(httpd_pid) 233 234 # wait() is not threadsafe and can throw OSError due to: 235 # http://bugs.python.org/issue1731717 236 self._process.wait() 237 self._process = None 233 httpd_pid = None 234 if self._process: 235 httpd_pid = self._process.pid 236 self._port_obj._shut_down_http_server(httpd_pid) 237 238 if self._process: 239 # wait() is not threadsafe and can throw OSError due to: 240 # http://bugs.python.org/issue1731717 241 self._process.wait() 242 self._process = None -
trunk/Tools/Scripts/webkitpy/layout_tests/port/http_server_base.py
r85659 r85665 30 30 """Base class with common routines between the Apache and Lighttpd servers.""" 31 31 32 import errno33 32 import logging 34 import socket33 import os 35 34 import time 35 import urllib 36 36 37 37 from webkitpy.common.system import filesystem … … 40 40 41 41 42 class ServerError(Exception):43 pass44 45 46 42 class HttpServerBase(object): 47 43 48 44 def __init__(self, port_obj): 49 45 self._port_obj = port_obj 50 self._executive = port_obj._executive51 self._filesystem = port_obj._filesystem52 self._process = None53 46 54 47 def wait_for_action(self, action): … … 64 57 return False 65 58 66 def is_running(self):67 return self._process and self._process.returncode is None68 69 59 def is_server_running_on_all_ports(self): 70 60 """Returns whether the server is running on all the desired ports.""" 71 if not self._executive.check_running_pid(self._process.pid): 72 _log.debug("Server isn't running at all") 73 raise ServerError("Server exited") 61 for mapping in self.mappings: 62 if 'sslcert' in mapping: 63 http_suffix = 's' 64 else: 65 http_suffix = '' 74 66 75 for mapping in self.mappings: 76 s = socket.socket() 77 port = mapping['port'] 67 url = 'http%s://127.0.0.1:%d/' % (http_suffix, mapping['port']) 68 78 69 try: 79 s.connect(('localhost', port))80 _log.debug("Server running on %d" % port)70 response = urllib.urlopen(url, proxies={}) 71 _log.debug("Server running at %s" % url) 81 72 except IOError, e: 82 if e.errno not in (errno.ECONNREFUSED, errno.ECONNRESET): 83 raise 84 _log.debug("Server NOT running on %d: %s" % (port, e)) 73 _log.debug("Server NOT running at %s: %s" % (url, e)) 85 74 return False 86 finally: 87 s.close() 75 88 76 return True 89 77 90 def check_that_all_ports_are_available(self):91 for mapping in self.mappings:92 s = socket.socket()93 port = mapping['port']94 try:95 s.bind(('localhost', port))96 except IOError, e:97 if e.errno in (errno.EALREADY, errno.EADDRINUSE):98 raise ServerError('Port %d is already in use.' % port)99 else:100 raise ServerError('Unexpected error: %s.' % str(e))101 finally:102 s.close()103 104 78 def remove_log_files(self, folder, starts_with): 105 files = self._filesystem.listdir(folder)79 files = os.listdir(folder) 106 80 for file in files: 107 81 if file.startswith(starts_with): 108 full_path = self._filesystem.join(folder, file)109 self._filesystem.remove(full_path)82 full_path = os.path.join(folder, file) 83 filesystem.FileSystem().remove(full_path) -
trunk/Tools/Scripts/webkitpy/layout_tests/port/websocket_server.py
r85659 r85665 41 41 import tempfile 42 42 import time 43 43 import urllib 44 45 import factory 44 46 import http_server 45 import http_server_base46 47 47 48 from webkitpy.common.system.executive import Executive … … 55 56 _DEFAULT_WS_PORT = 8880 56 57 _DEFAULT_WSS_PORT = 9323 58 59 60 def url_is_alive(url): 61 """Checks to see if we get an http response from |url|. 62 We poll the url 20 times with a 0.5 second delay. If we don't 63 get a reply in that time, we give up and assume the httpd 64 didn't start properly. 65 66 Args: 67 url: The URL to check. 68 Return: 69 True if the url is alive. 70 """ 71 sleep_time = 0.5 72 wait_time = 10 73 while wait_time > 0: 74 try: 75 response = urllib.urlopen(url, proxies={}) 76 # Server is up and responding. 77 return True 78 except IOError: 79 pass 80 # Wait for sleep_time before trying again. 81 wait_time -= sleep_time 82 time.sleep(sleep_time) 83 84 return False 85 86 87 class PyWebSocketNotStarted(Exception): 88 pass 89 90 91 class PyWebSocketNotFound(Exception): 92 pass 57 93 58 94 … … 83 119 self._pidfile = pidfile 84 120 self._wsout = None 85 self.mappings = []86 121 87 122 # Webkit tests … … 104 139 return 105 140 if self.is_running(): 106 raise http_server_base.ServerError('%s is already running.' % self._server_name) 141 raise PyWebSocketNotStarted('%s is already running.' % 142 self._server_name) 107 143 108 144 time_str = time.strftime('%d%b%Y-%H%M%S') … … 114 150 115 151 # Remove old log files. We only need to keep the last ones. 116 # Don't worry too much if this fails. 117 try: 118 self.remove_log_files(self._output_dir, log_prefix) 119 except OSError, e: 120 _log.warning('Failed to remove old websocket server log files') 121 pass 152 self.remove_log_files(self._output_dir, log_prefix) 122 153 123 154 error_log = os.path.join(self._output_dir, log_file_name + "-err.txt") … … 161 192 env.get('PYTHONPATH', '')) 162 193 163 self.mappings = [{'port': self._port}]164 self.check_that_all_ports_are_available()165 166 194 _log.debug('Starting %s server on %d.' % ( 167 195 self._server_name, self._port)) … … 175 203 env=env) 176 204 177 server_started = self.wait_for_action(self.is_server_running_on_all_ports) 178 if not server_started or self._process.returncode != None: 179 raise http_server_base.ServerError('Failed to start websocket server on port %d.' % self._port) 205 if self._use_tls: 206 url = 'https' 207 else: 208 url = 'http' 209 url = url + '://127.0.0.1:%d/' % self._port 210 if not url_is_alive(url): 211 if self._process.returncode == None: 212 # FIXME: We should use a non-static Executive for easier 213 # testing. 214 Executive().kill_process(self._process.pid) 215 with codecs.open(output_log, "r", "utf-8") as fp: 216 for line in fp: 217 _log.error(line) 218 raise PyWebSocketNotStarted( 219 'Failed to start %s server on port %s.' % 220 (self._server_name, self._port)) 221 222 # Our process terminated already 223 if self._process.returncode != None: 224 raise PyWebSocketNotStarted( 225 'Failed to start %s server.' % self._server_name) 180 226 if self._pidfile: 181 227 with codecs.open(self._pidfile, "w", "ascii") as file: … … 194 240 195 241 if not pid: 196 raise http_server_base.ServerError('Failed to find %s server pid.' % self._server_name) 242 raise PyWebSocketNotFound( 243 'Failed to find %s server pid.' % self._server_name) 197 244 198 245 _log.debug('Shutting down %s server %d.' % (self._server_name, pid)) 199 self._port_obj._executive.kill_process(pid) 246 # FIXME: We should use a non-static Executive for easier testing. 247 Executive().kill_process(pid) 200 248 201 249 if self._process:
Note: See TracChangeset
for help on using the changeset viewer.