Merge pull request #2625 from brendandahl/threaded-server
Switch to threaded python server for tests.
This commit is contained in:
commit
c9218e5aad
11
test/test.py
11
test/test.py
@ -15,9 +15,10 @@
|
|||||||
import json, platform, os, shutil, sys, subprocess, tempfile, threading
|
import json, platform, os, shutil, sys, subprocess, tempfile, threading
|
||||||
import time, urllib, urllib2, hashlib, re, base64, uuid, socket, errno
|
import time, urllib, urllib2, hashlib, re, base64, uuid, socket, errno
|
||||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||||
import SocketServer
|
from SocketServer import ThreadingMixIn
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from urlparse import urlparse, parse_qs
|
from urlparse import urlparse, parse_qs
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
USAGE_EXAMPLE = "%prog"
|
USAGE_EXAMPLE = "%prog"
|
||||||
|
|
||||||
@ -35,6 +36,8 @@ BROWSER_TIMEOUT = 60
|
|||||||
|
|
||||||
SERVER_HOST = "localhost"
|
SERVER_HOST = "localhost"
|
||||||
|
|
||||||
|
lock = Lock()
|
||||||
|
|
||||||
class TestOptions(OptionParser):
|
class TestOptions(OptionParser):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
OptionParser.__init__(self, **kwargs)
|
OptionParser.__init__(self, **kwargs)
|
||||||
@ -134,8 +137,8 @@ class Result:
|
|||||||
self.failure = failure
|
self.failure = failure
|
||||||
self.page = page
|
self.page = page
|
||||||
|
|
||||||
class TestServer(SocketServer.TCPServer):
|
class TestServer(ThreadingMixIn, HTTPServer):
|
||||||
allow_reuse_address = True
|
pass
|
||||||
|
|
||||||
class TestHandlerBase(BaseHTTPRequestHandler):
|
class TestHandlerBase(BaseHTTPRequestHandler):
|
||||||
# Disable annoying noise by default
|
# Disable annoying noise by default
|
||||||
@ -243,6 +246,7 @@ class UnitTestHandler(TestHandlerBase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
|
with lock:
|
||||||
url = urlparse(self.path)
|
url = urlparse(self.path)
|
||||||
numBytes = int(self.headers['Content-Length'])
|
numBytes = int(self.headers['Content-Length'])
|
||||||
content = self.rfile.read(numBytes)
|
content = self.rfile.read(numBytes)
|
||||||
@ -310,6 +314,7 @@ class PDFTestHandler(TestHandlerBase):
|
|||||||
|
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
|
with lock:
|
||||||
numBytes = int(self.headers['Content-Length'])
|
numBytes = int(self.headers['Content-Length'])
|
||||||
|
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user