summaryrefslogtreecommitdiffstats
path: root/net/tools/testserver/testserver.py
diff options
context:
space:
mode:
authortimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 14:50:58 +0000
committertimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 14:50:58 +0000
commit298883bc55dec7bbcb59897b919d9e07691d0da9 (patch)
tree36ef93371d363ce52e171043133ea56fe8fc48d2 /net/tools/testserver/testserver.py
parent2144db715de5552a67f34552c36a5cb3dba2ebd8 (diff)
downloadchromium_src-298883bc55dec7bbcb59897b919d9e07691d0da9.zip
chromium_src-298883bc55dec7bbcb59897b919d9e07691d0da9.tar.gz
chromium_src-298883bc55dec7bbcb59897b919d9e07691d0da9.tar.bz2
Re-apply http://codereview.chromium.org/1622012
It was reverted as http://codereview.chromium.org/1822001 the fix in Valgrind scripts has been commited as http://codereview.chromium.org/1736026 TEST=trybots Review URL: http://codereview.chromium.org/1763023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46070 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools/testserver/testserver.py')
-rw-r--r--net/tools/testserver/testserver.py61
1 files changed, 58 insertions, 3 deletions
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py
index 94ad3da..8e3df5e 100644
--- a/net/tools/testserver/testserver.py
+++ b/net/tools/testserver/testserver.py
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
-# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+# Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -22,9 +22,13 @@ import shutil
import SocketServer
import sys
import time
+import urllib2
+
+import pyftpdlib.ftpserver
import tlslite
import tlslite.api
-import pyftpdlib.ftpserver
+
+import chromiumsync
try:
import hashlib
@@ -125,12 +129,14 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.ContentTypeHandler,
self.ServerRedirectHandler,
self.ClientRedirectHandler,
+ self.ChromiumSyncTimeHandler,
self.MultipartHandler,
self.DefaultResponseHandler]
self._post_handlers = [
self.WriteFile,
self.EchoTitleHandler,
self.EchoAllHandler,
+ self.ChromiumSyncCommandHandler,
self.EchoHandler] + self._get_handlers
self._put_handlers = [
self.WriteFile,
@@ -149,6 +155,8 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request,
client_address,
socket_server)
+ # Class variable; shared across requests.
+ _sync_handler = chromiumsync.TestServer()
def _ShouldHandleRequest(self, handler_name):
"""Determines if the path can be handled by the handler.
@@ -996,6 +1004,39 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
return True
+ def ChromiumSyncTimeHandler(self):
+ """Handle Chromium sync .../time requests.
+
+ The syncer sometimes checks server reachability by examining /time.
+ """
+ test_name = "/chromiumsync/time"
+ if not self._ShouldHandleRequest(test_name):
+ return False
+
+ self.send_response(200)
+ self.send_header('Content-type', 'text/html')
+ self.end_headers()
+ return True
+
+ def ChromiumSyncCommandHandler(self):
+ """Handle a chromiumsync command arriving via http.
+
+ This covers all sync protocol commands: authentication, getupdates, and
+ commit.
+ """
+ test_name = "/chromiumsync/command"
+ if not self._ShouldHandleRequest(test_name):
+ return False
+
+ length = int(self.headers.getheader('content-length'))
+ raw_request = self.rfile.read(length)
+
+ http_response, raw_reply = self._sync_handler.HandleCommand(raw_request)
+ self.send_response(http_response)
+ self.end_headers()
+ self.wfile.write(raw_reply)
+ return True
+
def MultipartHandler(self):
"""Send a multipart response (10 text/html pages)."""
test_name = "/multipart"
@@ -1125,13 +1166,24 @@ def MakeDataDir():
# Create the default path to our data dir, relative to the exe dir.
my_data_dir = os.path.dirname(sys.argv[0])
my_data_dir = os.path.join(my_data_dir, "..", "..", "..", "..",
- "test", "data")
+ "test", "data")
#TODO(ibrar): Must use Find* funtion defined in google\tools
#i.e my_data_dir = FindUpward(my_data_dir, "test", "data")
return my_data_dir
+def TryKillingOldServer(port):
+ # Note that an HTTP /kill request to the FTP server has the effect of
+ # killing it.
+ for protocol in ["http", "https"]:
+ try:
+ urllib2.urlopen("%s://localhost:%d/kill" % (protocol, port)).read()
+ print "Killed old server instance on port %d (via %s)" % (port, protocol)
+ except urllib2.URLError:
+ # Common case, indicates no server running.
+ pass
+
def main(options, args):
# redirect output to a log file so it doesn't spam the unit test output
logfile = open('testserver.log', 'w')
@@ -1139,6 +1191,9 @@ def main(options, args):
port = options.port
+ # Try to free up the port if there's an orphaned old instance.
+ TryKillingOldServer(port)
+
if options.server_type == SERVER_HTTP:
if options.cert:
# let's make sure the cert file exists.