add timeout to web_server.py for unit tests (it doesn't seem to die on windows otherwise)

This commit is contained in:
Arvid Norberg 2013-11-06 04:05:13 +00:00
parent 4f11258d36
commit 3c5ec23480
1 changed files with 10 additions and 8 deletions

View File

@ -6,6 +6,13 @@ import ssl
chunked_encoding = False
class http_server_with_timeout(BaseHTTPServer.HTTPServer):
allow_reuse_address = True
timeout = 120
def handle_timeout(self):
raise Exception('timeout')
class http_handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(s):
@ -127,15 +134,10 @@ if __name__ == '__main__':
chunked_encoding = sys.argv[2] != '0'
use_ssl = sys.argv[3] != '0'
# TODO: SSL support
http_handler.protocol_version = 'HTTP/1.1'
httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', port), http_handler)
httpd = http_server_with_timeout(('127.0.0.1', port), http_handler)
if use_ssl:
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='../ssl/server.pem', server_side=True)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
while True:
httpd.handle_request()